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
2978
votes
21 answers

How do I modify the URL without reloading the page?

Is there a way I can modify the URL of the current page without reloading the page? I would like to access the portion before the # hash if possible. I only need to change the portion after the domain, so it's not like I'm violating cross-domain…
Robin Rodricks
  • 110,798
  • 141
  • 398
  • 607
554
votes
25 answers

Generic htaccess redirect www to non-www

I would like to redirect www.example.com to example.com. The following htaccess code makes this happen: RewriteCond %{HTTP_HOST} ^www\.example\.com [NC] RewriteRule ^(.*)$ http://example.com/$1 [L,R=301] But, is there a way to do this in a generic…
deepwell
  • 20,195
  • 10
  • 33
  • 39
401
votes
9 answers

When should I use a trailing slash in my URL?

When should a trailing slash be used in a URL? For example - should my URL look like /about-us/ or like /about-us? I am fully aware of the SEO-related issues - duplicate content and the canonical thing; I'm trying to figure out which one I should…
Denis
  • 4,718
  • 5
  • 18
  • 20
204
votes
10 answers

Setup nginx not to crash if host in upstream is not found

We have several rails apps under common domain in Docker, and we use nginx to direct requests to specific apps. our_dev_server.com/foo # proxies to foo app our_dev_server.com/bar # proxies to bar Config looks like this: upstream foo { server…
Morozov
  • 2,719
  • 2
  • 21
  • 23
175
votes
14 answers

How can I easily fixup a past commit?

I just read amending a single file in a past commit in git but unfortunately the accepted solution 'reorders' the commits, which is not what I want. So here's my question: Every now and then, I notice a bug in my code while working on an (unrelated)…
Frerich Raabe
  • 90,689
  • 19
  • 115
  • 207
175
votes
8 answers

Redirect all to index.php using htaccess

I am writing a simple PHP-based MVC-ish framework. I want this framework to be able to be installed in any directory. My PHP script grabs the request uri and breaks it off into segments. It makes segment 1 the controller and segment 2 the action.…
David Ericsson
  • 2,570
  • 2
  • 19
  • 33
160
votes
6 answers

.htaccess mod_rewrite - how to exclude directory from rewrite rule

I have 8 lines of rewrite rules in my .htaccess file. I need to exclude two physical directories on my server from these rules, so they can become accessible. For now all requests are sent to index.php file. Directories to exclude: "admin" and…
Kelvin
  • 8,813
  • 11
  • 38
  • 36
155
votes
5 answers

URL rewriting with PHP

I have a URL that looks like: url.com/picture.php?id=51 How would I go about converting that URL to: picture.php/Some-text-goes-here/51 I think WordPress does the same. How do I go about making friendly URLs in PHP?
Jazerix
  • 4,729
  • 10
  • 39
  • 71
151
votes
4 answers

How to redirect a URL in Nginx

I need to redirect every http://test.com request to http://www.test.com. How can this be done. In the server block I tried adding rewrite ^/(.*) http://www.test.com/$1 permanent; but in browser it says The page isn't redirecting properly Firefox…
Amal Kumar S
  • 15,555
  • 19
  • 56
  • 88
150
votes
9 answers

How do I configure IIS for URL Rewriting an AngularJS application in HTML5 mode?

I have the AngularJS seed project and I've added $locationProvider.html5Mode(true).hashPrefix('!'); to the app.js file. I want to configure IIS 7 to route all requests to http://localhost/app/index.html so that this works for me. How do I do…
Dean
  • 4,554
  • 7
  • 34
  • 45
140
votes
17 answers

Gmail's new image caching is breaking image links in newsletter

I've got some automatic emails that are sent out upon signup completion for my site. Until recently, they worked fine. Now Google's new system is rewriting the images and storing them in its cache (supposedly) However, Google's new rewriting of my…
RonnyKnoxville
  • 6,166
  • 10
  • 46
  • 75
134
votes
19 answers

How to check whether mod_rewrite is enable on server?

Currently I am using the hosting with lightspeed server. Hosting says mod_rewrite is enabled but I can't get my script working there. Whenever I try to access the URL, it returns 404 - not found page. I put the same codes at another server which is…
knightrider
  • 2,533
  • 7
  • 30
  • 42
126
votes
3 answers

How to redirect single URL in Nginx?

I'm in the process of reorganizing URL structure. I need to setup redirect rules for specific URLs - I'm using Nginx. Basically Something like this: http://example.com/issue1 -->…
tokmak
  • 1,489
  • 2
  • 12
  • 16
116
votes
27 answers

How to remove "index.php" in codeigniter's path

How do I remove the "index.php" sticking out in every path in codeigniter somewhere in the center? I want clean non index.php-fied URLs?
OrangeRind
  • 4,798
  • 13
  • 45
  • 57
99
votes
1 answer

IIS URL Rewrite {R:N} clarification

I've not been able to understand the purpose of {R:N}. Could anyone please clarify when to use {R:0} vs. {R:1} usage example: I've seen ScottGu using…
Nil Pun
  • 17,035
  • 39
  • 172
  • 294
1
2 3
99 100