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
19
votes
1 answer

Pretty URLs in PHP frameworks

I know that you can add rules in htaccess, but I see that PHP frameworks don't do that and somehow you still have pretty URLs. How do they do that if the server is not aware of the URL rules? I've been looking Yii's url manager class but I don't…
Alex
  • 66,732
  • 177
  • 439
  • 641
19
votes
4 answers

Auto-versioning in ASP.NET MVC for CSS / JS Files?

I have read lots of article on how to auto-version your CSS/JS files - but none of these really provide an elegant way to do this in ASP.NET MVC. This link - How to force browser to reload cached CSS/JS files? - provides a solution for Apache - but…
Tom
  • 193
  • 1
  • 1
  • 5
19
votes
6 answers

How to handle diacritics (accents) when rewriting 'pretty URLs'

I rewrite URLs to include the title of user generated travelblogs. I do this for both readability of URLs and SEO purposes. http://www.example.com/gallery/280-Gorges_du_Todra/ The first integer is the id, the rest is for us humans (but is…
Jacco
  • 23,534
  • 17
  • 88
  • 105
19
votes
2 answers

How to remove a subdirectory from the url before passing to a script?

This has been asked on SO before but the answers have not been generalized. So here goes. I have two different web apps. They were made to be on different servers at the root. But now they are going to be placed into subdirectories on the same…
101010
  • 14,866
  • 30
  • 95
  • 172
19
votes
4 answers

Wordpress: include language variable in url

I have been developing a language plugin for wordpress which works completely. The only thing that is missing now is the url-rewriting. I have been looking at a lot of websites, sources and other questions on stackoverflow, but I can't seem to get…
Michiel Standaert
  • 4,096
  • 7
  • 27
  • 49
19
votes
2 answers
19
votes
1 answer

nginx - redirect a certain path to another domain

I am very unfamiliar with nginx, as a forewarning, and also can't find any actual references on the regex system they use. So right now it's a black box to me. All I want to do is redirect a user trying to go to www.mydomain.com/mydirectory/X to…
Eli
  • 4,874
  • 6
  • 41
  • 50
19
votes
3 answers

Apache rewrite rule with parameters?

I have the following URL: http://domain.com/index.php?m=feedback&cSubject=My Subject I want to have a rewrite rule so that the following: http://domain.com/feedback?Subject=My Subject maps to the previous url. Heres my rule at the…
James
  • 80,725
  • 18
  • 167
  • 237
19
votes
1 answer

How to exclude a specific file from a rewriterule

I have been here: How to exclude a specific file in htaccess and here: exclude files from rewrite rule in .htaccess but neither worked. What might I be doing wrong? .htaccess file: RewriteEngine On RewriteRule…
Christian
  • 735
  • 3
  • 10
  • 29
18
votes
1 answer

How to control NGINX 'Location' directive matching order?

I'm trying to optimize my 'location' directives and cannot find a good way of determining if a specific location match is even attempted. Using echo inside the location block doesn't help here. The NGINX ngx_http_core_module documentation is…
leeoniya
  • 1,071
  • 1
  • 9
  • 25
18
votes
1 answer

.htaccess in subdirectory 'overriding' parent htaccess

been searching for 2 days and can't quite get the right solution due to my lack of understanding of mod_rewrite and time constraints on this project so hoping someone can help. The aim To rewrite all requests to the root index.php if the client…
Abe
  • 183
  • 1
  • 1
  • 4
18
votes
1 answer

The element > system.webServer' has invalid child > element 'rewrite'

Warning 1 The element 'system.webServer' has invalid child element 'rewrite'. List of possible elements expected: 'asp, caching, cgi, defaultDocument, directoryBrowse, globalModules, handlers, httpCompression, httpErrors, …
senzacionale
  • 20,448
  • 67
  • 204
  • 316
18
votes
10 answers

Redirect Non WWW to WWW using Asp.Net Core Middleware

On an ASP.Net Core application startup I have: RewriteOptions rewriteOptions = new RewriteOptions(); rewriteOptions.AddRedirectToHttps(); applicationBuilder.UseRewriter(rewriteOptions); When in Production I need to redirect all Non WWW to WWW…
Miguel Moura
  • 36,732
  • 85
  • 259
  • 481
18
votes
3 answers

ASP.NET MVC UrlHelper.GenerateUrl exception: "Cannot use a leading .. to exit above the top directory"

I am using the IIS 7 Rewrite module to rewrite an incoming url like: http://server/year/all to http://server/application/controller/year/all Everything works fine, except when, while processing the rewritten request, I use MVC's…
Paul Kearney - pk
  • 5,435
  • 26
  • 28
18
votes
4 answers

need to escape # (hash/pound) character in .htaccess rewrite rule

The question is fairly simple but I was not able to find an answer for hours now. What I need to do is: RewriteRule ([^#])#(.*) $1\%23$2 Which basically means I want to url escape the freaking hash sign which comes to me from an external…
kali
  • 1,143
  • 1
  • 9
  • 26