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
17
votes
2 answers

Haproxy route and rewrite based on URI path

I am trying to setup an Haproxy to load balance requests on a few backends identified by the uri path. For example: https://www.example.com/v1/catalog/foo/bar Should lead to the "catalog-v1" backends. Thing is each app responds on a different path…
leovrf
  • 605
  • 1
  • 6
  • 17
17
votes
1 answer

Modifying a Location header with nginx proxy_pass

I have an nginx proxy_pass setup to pass every request on /api through to a backend Tomcat REST service. This service in some cases returns a Location header which varies according to the type of request, e.g., Location:…
user2010963
  • 297
  • 1
  • 3
  • 8
17
votes
2 answers

How to disable 301 redirect that adds trailing slash to directory name in Apache

The Apache 2.2.20 automaticaly redirects all requests which are points to directories and has no trailing slash to the same URL with trailing slash, like shown below: GET /some/path/to/dir HTTP/1.1 Host: www.some.org ... 301 Moved…
kruz05
  • 501
  • 1
  • 9
  • 17
16
votes
2 answers

IIS Rewrite Input Types

What are the input types you can use in IIS rewrite rules? The ones I mean are like as follows: HTTP_HOST URL REQUEST_FILENAME ?
McGarnagle
  • 101,349
  • 31
  • 229
  • 260
16
votes
5 answers

How does url rewrite works?

How does web server implements url rewrite mechanism and changes the address bar of browsers? I'm not asking specific information to configure apache, nginx, lighthttpd or other! I would like to know what kind of information is sent to clients when…
cirne100
  • 1,558
  • 2
  • 12
  • 24
16
votes
2 answers

mod_rewrite NE flag - When is it helpful to encode special chars in the URL?

I've been looking at the [NE] (noescape) flag in mod_rewrite. After some thought I couldn't figure out a situation when I would NOT want to use the flag. Meaning, it seems most helpful to keep the flag enabled in almost every RewriteRule. Not…
Vahid Pazirandeh
  • 1,552
  • 3
  • 13
  • 29
16
votes
3 answers

Rewrite for an empty query string

I'm building in some caching to one of my sites, and I can't seem to find if there's a way to add a condition with mod_rewrite to apply only if the query string on a request is empty. For example, I'd love to know if I can have a request with no…
Justin Russell
  • 1,009
  • 1
  • 9
  • 15
16
votes
3 answers

Convert to lowercase in a mod_rewrite rule

I would like URLs like server.com/foo to be case-insensitive. But server.com/foo actually gets mod_rewrite'd to server.com/somedir/foo (Assume that all the files in "somedir" are lower case.) So the question is, how to accomplish a mod_rewrite like…
dreeves
  • 26,430
  • 45
  • 154
  • 229
16
votes
3 answers

Tomcat 8 URL Rewrite

I have an AngularJS webapp and Jersey backend. I need to setup URL rewriting, so everything except given exceptions will be rewritten to Angular's index.html. Eg.: http://my.domain.com/about will be rewritten http://my.domain.com/photos/photo1.jpg…
kamelot
  • 491
  • 1
  • 7
  • 19
16
votes
4 answers

How to get original url after HttpContext.RewritePath() has been called

I am working on a web app which makes use of a 3rd party HttpModule that performs url rewriting. I want to know if there's any way to determine the original url later on in Application_BeginRequest event. For example... Original…
jessegavin
  • 74,067
  • 28
  • 136
  • 164
16
votes
1 answer

How to exclude a directory with IIS URL rewriting?

I have a domain.com/index.php and a friendly url rule to redirect domain.com/index.php?s=? requests. I use IIS webserver with the URL rewrite add-on. Above works fine. However, there is a problem with requests to the admin directory... I also have…
Arjen
  • 289
  • 2
  • 4
  • 11
16
votes
1 answer

RewriteEngine On in every time?

I'm wondering whether I can use RewriteEngine On only once within my htaccess when it is embed in IfModule mod_rewrite.c or do I have to use it every time because it is embeded? See example below. Thanks RewriteEngine…
WendiT
  • 595
  • 2
  • 9
  • 26
16
votes
4 answers

URL rewriting via Wordpress Rewrite or .htaccess

JUMP TO EDIT8 TO SEE HOW I SOLVED THIS Let's say I have a Wordpress blog: www.animals.com. I have a certain PHP file in my theme directory: www.animals.com/wp-content/themes/mytheme/db.php. Also, I have a custom template for that page, so I create…
johnRivs
  • 135
  • 2
  • 4
  • 19
16
votes
3 answers

nginx /index.html to / rewrite

I am trying to rewrite /index.html to / for SEO purposes (stupid search engines which confuse index.html with / and penalize for duplicate content) -- also to reconcile web analytics data. I've tried every solution I've found on stackoverflow, nginx…
auralsun
  • 165
  • 1
  • 1
  • 7
16
votes
2 answers

Remove www. from host name using Nginx Rewrite

I am trying to configure my Nginx to strip out www. from hostname. I am looking for generic rule that handle possible subdomain cases. E.g. If http://www.foo1.sample.com and http://www.fooX2.sample.com are two domains. Then I want to strip any www.…
Tzahi Fridman
  • 320
  • 2
  • 7