Questions tagged [rewrite]

URL Rewriting maps an incoming URL to a modified URL, so that the request is processes as if the original request was made to the modified URL. This is often used to provide more search engine friendly URLs.

Filter by
Sorted by
Tagged with
89 votes
4 answers
342k views

Nginx Redirect via Proxy, Rewrite and Preserve URL

In Nginx we have been trying to redirect a URL as follows: http://example.com/some/path -> http://192.168.1.24 where the user still sees the original URL in their browser. Once the user is ...
robjohncox's user avatar
  • 1,045
90 votes
5 answers
111k views

What is the difference between Nginx variables $host, $http_host, and $server_name?

What is the difference between the three Nginx variables $host, $http_host, and $server_name? I have a rewrite rule where I'm not sure which one I should be using: location = /vb/showthread.php { ...
Jeff Widman's user avatar
  • 2,545
80 votes
11 answers
71k views

Remove "www" and redirect to "https" with nginx

I want to create a rule in nginx that does two things: Removes the "www." from the request URI Redirects to "https" if the request URI is "http" There are plenty of examples of how to do each of ...
Devin's user avatar
  • 923
20 votes
1 answer
21k views

maintaining redirects in nginx from an external source

I am in the situation to give our marketing department the opportunity to maintain their redirects by their own. Until now, they passed the information to the IT department and we maintained it for ...
Sascha's user avatar
  • 538
3 votes
1 answer
5k views

Nginx rewite rules 403 error

I am having trouble with converting .htaccess files to nginx. I have 3 .htaccess files. The first .htaccess file is located in the document root and is as follows: Options +FollowSymLinks ...
Adrian's user avatar
  • 67
21 votes
2 answers
79k views

nginx rewrite for an url with parameters

I have an URL of this type: http://www.example.com/?param1=val1&param2=&param3=val3&param4=val4&param5=val5 And I want to redirect it to this one: http://www.example.com/newparam/...
David Morales's user avatar
20 votes
3 answers
26k views

nginx case insensitive rewrite

I am trying to make my nginx redirects as clean as possible. I understand ~* is for case insensitive but I can only get it to work in example 2. Example 1 rewrite ^/foobar http://www.youtube.com/...
milleruni's user avatar
  • 303
81 votes
5 answers
361k views

Nginx redirect one path to another

I'm sure this has been asked before, but I can't find a solution that works. A website has switched CMS services, but has the same domain, how do I set up an nginx rewrite for a single page? E.g. ...
SteveEdson's user avatar
  • 1,549
9 votes
2 answers
45k views

nginx redirect to www.domain

I want to redirect the site ALWAYS to www.site.com. However, I am not sure as to how to get the WWW to always show up in front should say someone type in the domain without the www. EDIT: server { ...
Jake Thomas's user avatar
7 votes
1 answer
5k views

IIS 7.5 Redirect / URL Rewrite to mobile version of website

I'm looking for an IIS solution (not programming) to redirect a website to a mobile version of the website. It looks like it might be possible, but not sure, with IIS Redirect or using IIS URL Rewrite ...
thames's user avatar
  • 955
31 votes
3 answers
54k views

HAProxy reqrep remove URI on backend request

real quick question regarding HAProxy reqrep. I am trying to rewrite/replace the request that gets sent to the backend. I have the following example domain and URIs, both sharing the same domain ...
Jim's user avatar
  • 988
25 votes
4 answers
68k views

nginx + PHP-FPM = "permission denied" error 13 in nginx log; configuration mistake?

I've got nginx 0.7x + PHP-FPM running under PHP 5.2.10 on one RHEL5 server, but trying to duplicate that setup under the bundled-in PHP-FPM in PHP 5.3.3 on a second server, I'm having some trouble ...
Peter Kirn's user avatar
24 votes
10 answers
51k views

How to inject HTML code into every delivered HTML page?

I've got an Apache web server that delivers static HTML pages. For some reason I can't change the files themselves, but I still want to inject some HTML into every page that is being served. Is this ...
Node's user avatar
  • 1,644
17 votes
5 answers
2k views

How can I enforce that my urls always start with www?

I want to ensure that users come to www.mydomain.com even if they arrive through the alias mydomain.com. This is so that I have control over cookies on subdomains, and so that Google sees one single ...
Magnar's user avatar
  • 1,047
14 votes
2 answers
37k views

Nginx Rewrite Convert Querystring to Path

I whould like this simple rewrite rule: /somefolder/mypage.aspx?myid=4343&tab=overview to be redirected to: /folder/4343/overview/ I looked for some solutions and none actually worked.. I ...
YardenST's user avatar
  • 265
9 votes
1 answer
40k views

IIS URL Rewrite Module Query String Parameters

Is it possible to use URL Rewrite to provide more complex query string functionality than the "Append query string" checkbox that it has? Specifically, is it possible to specify the keys for certain ...
Jason Kresowaty's user avatar
8 votes
4 answers
72k views

How do you configure IIS 7 to use a subdirectory as the default document?

So I have a website running on a discount asp.net account, and I put an asp.net mvc app in a subdirectory. If my url is 'www.website.com' and my app is in directory 'sample', then 'www.website.com/...
Mark Rogers's user avatar
8 votes
4 answers
20k views

nginx subdomain rewrite

Yet another nginx rewrite rule question How can I do a rewrite from http://www.*.domain.com to http://*.domain.com ? thanks in advance -- Deb EDIT: I'm sorry I didn't see the textile formatting ...
deb's user avatar
  • 245
7 votes
1 answer
18k views

Url rewriting in Amazon S3

I have a webapp hosted in Amazon S3, the webapp is build with jQuery Mobile and I use changePage lo navigate between pages, I'm not using the hash operator(#) when I change the page. I'm having ...
Fernando P. G.'s user avatar
5 votes
4 answers
20k views

How to redirect non-www to www without hardcoding using .htaccess?

RewriteEngine On RewriteCond %{HTTPS} !=on RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC] RewriteRule ^(.*)$ http://%1/$1 [R=301,L] ...causes a perfect, non-hardcoding 301 redirect from "www to non-www", ...
user avatar
4 votes
2 answers
11k views

Clean URLs and php extension on nginx

I've looked at dozens of other questions and references on the web - and by all my calculations, my setup should work, but it doesn't. I have nginx installation with php-fpm. If I try to access a ....
Aleks G's user avatar
  • 986
4 votes
2 answers
5k views

Apache-style multiviews with Nginx

I'm interested in switching from Apache/mod_php to Nginx for some non-CMS sites I'm running. The sites in question are either completely static HTML files or simple PHP, but the one thing they have in ...
Kenn's user avatar
  • 145
4 votes
1 answer
4k views

Rewriting ASCII-percent-encoded locations to their UTF-8 encoded equivalent

For example, “å” can be encoded as /%E5 and /%C3%A5 (utf-8). All my filenames are UTF-8, so the ASCII variants return a 404. I want both variants to work. I have tried rewriting the incorrect URLs to ...
Daniel's user avatar
  • 221
3 votes
2 answers
309 views

Is there an Elegant solution to rewrite long image?query-urls into cachable_nice_urls, using only apache htaccess?

this is a pain in the ass-problem! Whicever genius solves this riddle will receive paypal donation to eat diner for two. Now lets get started. Given: most proxies, do not cache resources with a "?" in ...
Sam's user avatar
  • 423
3 votes
2 answers
3k views

Redirecting www to non-www (apache, letsencrypt )

Ubuntu 14.04 Apache 2.4.18 I have set up a SSL certificate using letsencrypt. It works well but in order to work, I cannot have multiple vhost defined in one virtualhost configuration file. Each ...
pixeline's user avatar
  • 658
2 votes
3 answers
12k views

Nginx serve plain file if exists else serve /index.php

I want Nginx to serve any requests for static files on its own, but if the file doesn't exist, then serve index.php which will handle it all Currently my configuration looks like this, server { ...
John Cave's user avatar
  • 318
2 votes
3 answers
4k views

Does OpenLiteSpeed support Apache .htaccess rewrites?

I have been getting some conflicting information - official OpenLiteSpeed pages say both that: OpenLiteSpeed supports Apache rewrites, and OpenLiteSpeed does not support .htaccess A bit confused......
Helene's user avatar
  • 47
1 vote
1 answer
867 views

nginx append query parameter to a react application

I am a beginner in Nginx and I want to append a query parameter to the URL (for instance myid) in order to serve a react application. I am using nginx/1.18.0 (Ubuntu) There are similar questions like: ...
Ximo Dante's user avatar
1 vote
1 answer
616 views

Using Virtual Domains with WordPress and Cherokee Web Server

I'm trying to configure WordPress to work with Cherokee Web Server. The multi-site set up in WordPress is yyy.com and uses 'sub-domains'. Thus, I have sites like aaa.yyy.com, bbb.yyy.com - they all ...
ikevin8me's user avatar
  • 137
-3 votes
2 answers
957 views

How do I redirect .php pages to .html pages? [duplicate]

Possible Duplicate: Everything You Ever Wanted to Know about Mod_Rewrite Rules but Were Afraid to Ask? I have a dynamic website, so all the pages are in .php, but I want to show an address ending ...
dasarath sahoo's user avatar
80 votes
2 answers
93k views

nginx url rewriting: difference between break and last

I don't understand the difference between break and last (flags of rewrite). The documentation is rather abstruse. I've tried to switch between the two in some of my configs, but I couldn't spot any ...
user avatar
48 votes
2 answers
117k views

How to quick and easy remove part of an URL in Nginx with HttpRewriteModule?

I know about the HttpRewriteModule, but I don't really know how to handle regex and I would need to redirect all URLs within a certain directory to another, specifically: From: example.com/component/...
javipas's user avatar
  • 1,362
39 votes
3 answers
120k views

How to rewrite the domain part of Set-Cookie in a nginx reverse proxy?

I have a simple nginx reverse proxy: server { server_name external.domain.com; location / { proxy_pass http://backend.int/; } } The problem is that Set-Cookie response headers contain ;...
Tobia's user avatar
  • 1,203
35 votes
2 answers
56k views

Disabling URL decoding in nginx proxy

When I browse to this URL: http://localhost:8080/foo/%5B-%5D server (nc -l 8080) receives it as-is: GET /foo/%5B-%5D HTTP/1.1 However when I proxy this application via nginx (1.1.19): location /foo ...
Tomasz Nurkiewicz's user avatar
23 votes
2 answers
22k views

Redirect only home page

I need to redirect only http://shop.test.com to http://www.test.com/fedex-orders/ Just homepage. Nothing else. ie http://shop.test.com/?page=blog should NOT redirect.
Harikrishnan's user avatar
  • 1,249
17 votes
2 answers
19k views

"Hide" .html file extensions using nginx rewrites

I'm serving up a static site via nginx, and my goal is to replace URL's that look like: http://foo.com/bar.html with http://foo.com/bar The key being no trailing slash. I am currently doing ...
Doug Stephen's user avatar
15 votes
3 answers
71k views

Nginx rewrite URL only if file exists

I need to write a rewrite rule for Nginx so that if a user tries to go to an old image url: /images/path/to/image.png and the file doesnt exist, try to redirect to: /website_images/path/to/image....
Jose Fernandez's user avatar
12 votes
3 answers
29k views

Temporarily redirect *all* HTTP/HTTPS requests in IIS to a "server maintenance" page

We've got an IIS server that hosts hundreds of separate web apps, and the physical database server that hosts these apps is going to be taken offline for maintenance for a brief period (we expect it ...
Josh's user avatar
  • 287
11 votes
3 answers
65k views

Add samesite to cookies using Nginx as reverse proxy

With Nginx as reverse proxy, how do you add samesite=strict or samesite=lax to cookies?
Dr.Haribo's user avatar
  • 213
11 votes
1 answer
19k views

How to extract Only the file name from the request uri

I am trying to rewrite the request uri depending on the extension of the file, then extract only the file name from the uri and store it in another folder. The problem here is no predefined variable ...
Johnta's user avatar
  • 113
10 votes
3 answers
29k views

Apache: Where to examine the redirection logs?

I have complicated RewriteCond and RewriteRule in one machine. And according to these rules, some of the requests will be redirected to another machine. So is there any Apache log that shows clearly ...
Graviton's user avatar
  • 2,925
10 votes
3 answers
31k views

How do I make RewriteCond %{HTTP_COOKIE} match a cookie value exactly? [duplicate]

How do I make my rule match an exact value of a cookie? I've tried: RewriteCond %{HTTP_COOKIE} ^its=me$ [NC] RewriteCond %{HTTP_COOKIE} its=^me$ [NC] RewriteCond %{HTTP_COOKIE} its="me" [NC] ...
Nick's user avatar
  • 4,656
7 votes
2 answers
13k views

Rewrite URL before passing to proxy Lighttpd

I'm trying to setup a reverse proxy in lighttpd, such that all requests (and only those requests) under /mobile/video is redirected to the / directory of a secondary web server. This is pretty easy in ...
futureelite7's user avatar
7 votes
2 answers
6k views

How to port Apache rewrite rules to cherokee?

I'm pretty new to cherokee, it's great and pretty straight forward except URL Rewrites. Is there a straight forward guide to it? Let me know. Also how would I port this: RewriteEngine on RewriteCond ...
0xdeadbeef's user avatar
5 votes
3 answers
7k views

Redirect http://example.com:12345 to https://example.com:12345 in nginx

I know this must have been answered already, but I have been searching for quite a while, and cannot find the answer. Just not looking in the right place I guess, maybe someone can help me out. ...
Saif Bechan's user avatar
5 votes
2 answers
6k views

Redirecting to the IP of an amazon EC2 instance

As you know amazon EC2 instances get an address like: ec2-72-44-40-153.z-2.compute-1.amazonaws.com If I have the domain example.com, is there any way that I can make bob.example.com or preferably ...
user avatar
3 votes
1 answer
16k views

Rewrite on root of domain only in nginx

I've got YOURLS server running to host short urls for my company, so that we can provide short URL's to our customers. I'm using nginx, and for root of the domain, if they aren't using a proper short ...
user217761's user avatar
3 votes
2 answers
6k views

Redirect wildcard subdomain to same subdomain on different domain

I have a domain with dynamic subdomains. The domain, unfortunately, has changed. As such I need to redirect *.domain1.com to *.domain2.com while keeping the subdomains the same. I have looked ...
Joseph's user avatar
  • 161
3 votes
2 answers
7k views

nginx sub directory wildcard rewrite

I have set up a server block on my nginx server, e.g. with domain testsite.com. I want to be able to install separate WordPress installations into direct child folders of the root folders, e.g. /var/...
physalis's user avatar
  • 145
3 votes
1 answer
130 views

Multiple rule Apache rewrite

I am trying to set up a hierarchy five levels deep with mod_rewrite. This is what I have put together at this point. It works for the last two levels (the first and second rule) but not after that. ...
xxx's user avatar
  • 33