Questions tagged [url-rewriting]

A URL rewrite engine is software that modifies a web URL's appearance (URL rewriting). Rewritten URLs are used to provide shorter and more relevant-looking links to web pages, to route users from obsolete URLs to replacements, or to simplify the format of the URL for human readability. The technique adds a degree of separation between the files used to generate a web page and the URL that is presented to the world.

A URL rewrite engine, part of a web server's URL-to-filename mapping engines, is software that modifies a web URL's appearance (URL rewriting). Rewritten URLs (sometimes known as short, fancy URLs, or search engine friendly - SEF) are used to provide shorter and more relevant-looking links to web pages, to route users from obsolete URLs to replacements, or to simplify the format of the URL for human readability. The technique adds a degree of separation between the files used to generate a web page and the URL that is presented to the world. It is integral in frameworks that route all URI requests through a routing script or a controller.

Useful links

  1. and its tag-wiki for some examples regarding the most widely-used implementation for the Apache web server.
  2. and its tag-wiki for an implementation for java/j2EE technology.
20479 questions
28
votes
2 answers

rewrite a folder name using .htaccess

I am wondering wether it's possible to use .htaccess to rewrite a folder name. What I mean is this. Lets say I have a url like: www.site.com/folder1/page.php Now I want to rewrite the url to (for example) www.site.com/apple/page.php The folder1…
sanders
  • 10,794
  • 27
  • 85
  • 127
27
votes
4 answers

How long does it take for .htaccess changes to take effect?

I have added url rewrite rules to my .htaccess file. Should I see these changes working right away?
dev.e.loper
  • 35,446
  • 76
  • 161
  • 247
27
votes
4 answers

Apache 2.4 - Request exceeded the limit of 10 internal redirects due to probable configuration error

I'm running Apache 2.4 (64bit) and PHP 5.4.15 on windows Server 2008 R2 Enterprise and have noticed the following error in the Apache error log: AH00124: Request exceeded the limit of 10 internal redirects due to probable configuration error. Use…
iltdev
  • 1,789
  • 9
  • 27
  • 51
27
votes
7 answers

Redirect 301 with hash part (anchor) #

One of our website has URL like this : example.oursite.com. We decided to move our site with an URL like this www.oursite.com/example. To do this, we wrote a rewrite rule in our Apache server that redirect to our new URL with a code 301. Many…
Mike
26
votes
5 answers

mod_rewrite: remove trailing slash (only one!)

I use mod_rewrite/.htaccess for pretty URLs. I'm using this condition/rule to eliminate trailing slashes (or rather: rewrite to the non-trailing-slash-URL, by a 301 redirect; I'm doing this to avoid duplicate content and because I like URLs with no…
user367217
  • 499
  • 2
  • 6
  • 20
26
votes
4 answers

Set RewriteBase to the current folder path dynamically

Is there any way to set RewriteBase to the path current folder (the folder which the .htaccess file is in) relative to the host root? I have a CMS and if I move it to the directory in my host it does not work unless I set the RewriteBase to the path…
Eeliya
  • 1,534
  • 5
  • 23
  • 37
26
votes
9 answers

.htaccess not working on localhost with XAMPP

i m using XAMPP but i m not able to use .htaccess file at local host. i m trying so many times.. Online working good. but local host showing [The requested URL was not found on this server] My root folder is…
acre
  • 283
  • 2
  • 4
  • 6
26
votes
5 answers

rewrite rules for apache 2 to use with angular js

Obviously, there are a lot of mod rewrite discussions and answers all across the web. However, I am having a hard time grasping them. So I thought I would ask here. I'm asking for rewrite rules to do what Andy Joslin explained in the comments here:…
Mike Haas
  • 2,273
  • 3
  • 25
  • 30
26
votes
2 answers

How to make .htaccess RewriteCond check domain name?

I have this rule: RewriteRule ^(about|installation|mypages|privacy|terms)(/)*$ /index.php?kind=portal&id=1&page=$1&%{QUERY_STRING} [L] How can I change it so that it would work only for a specific domain, www.domain.com for example?
D_R
  • 4,894
  • 4
  • 45
  • 62
25
votes
2 answers

nginx rewrite redirect for a folder

all... I am trying to do something in nginx to redirect all calls for files in /images/ to become in: /assets/images/ can someone help me with the rewrite rule? giving a 301 moved permanently status?
alybadawy
  • 489
  • 2
  • 7
  • 13
24
votes
5 answers

convert htaccess to nginx

I'm having no luck converting htaccess rules to nginx rewrite. I've checked out the NginxRewriteModule documentation and have a few done, but the more complicate ones I'm at a loss for. Here's what I'm looking at: RewriteRule ^$ …
cheifops
  • 309
  • 1
  • 3
  • 6
24
votes
8 answers

.htaccess redirect subfolder to HTTPS

I'm trying to write a RewriteRule for my .htaccess file. Specifically, whenever a user accesses a specific subdirectory, I would like it to Rewrite to force an HTTPS connection. For example, whenever someone accesses:…
Dodinas
  • 6,705
  • 22
  • 76
  • 108
24
votes
4 answers

Apache rewrite rule which works with or without a trailing slash

I'm trying to redirect a series of static URLs, and I want it to work whether or not the trailing slash is present: /foo/bar ---> /tacos /foo/bar/ --> /tacos I've tried the following, and all sorts of variations, but I always get a match only…
Luke Dennis
  • 14,212
  • 17
  • 56
  • 69
24
votes
2 answers

Use 301 or 303 to redirect http to https

I'm not sure which is the best to use for my site when redirecting from http to https. At the moment I am using IIS rewrite rules to do the redirect. The guides I've read on how to do this use either a 301 or a 303. And after reading up on 301 and…
garethb
  • 3,951
  • 6
  • 32
  • 52
24
votes
4 answers

IIS7 URL Rewriting: How not to drop HTTPS protocol from rewritten URL?

I'm working on a website that uses IIS 7's URL rewriting feature to do a permanent redirect from example.com to www.example.com, as well as rewrites from similar domain names to the "main" one, such as from www.examples.com to www.example.com. This…
Scott Mitchell
  • 8,659
  • 3
  • 55
  • 71