Skip to main content

Questions tagged [mod-rewrite]

mod_rewrite is an Apache module that allows for server-side manipulation of requested URLs.

Filter by
Sorted by
Tagged with
285 votes
5 answers
117k views

Redirect, Change URLs or Redirect HTTP to HTTPS in Apache - Everything You Ever Wanted to Know About mod_rewrite Rules but Were Afraid to Ask

This is a Canonical Question about Apache's mod_rewrite. Changing a request URL or redirecting users to a different URL than the one they originally requested is done using mod_rewrite. This includes ...
Kyle Brandt's user avatar
  • 84.6k
72 votes
4 answers
297k views

Redirect URL within Apache VirtualHost?

I have a dedicated server with Apache, on which I've set up some VirtualHosts. I've set up one to handle the www domain as well as the non-www domain. My VH .conf file for the www: <VirtualHost *&...
DisgruntledGoat's user avatar
70 votes
4 answers
100k views

best way to debug nginx rewrite rules in config file?

I have a bunch of rewrite rules that I have to port from apache to nginx. It's a rather painful process because I'm not able to see if my rewrite rules and "if" conditions are working as I want them ...
Jiho Kang's user avatar
  • 1,107
36 votes
3 answers
59k views

How to Exclude an URL for Apache Mod_proxy?

We have two Apache server as front-end and 4 tomcat server as back-end configured using mod_proxy module as load balancer. Now, we want to exclude an single tomcat url from the mod_proxy load balancer....
Mughil's user avatar
  • 1,969
20 votes
9 answers
76k views

How to I test if mod_rewrite is enabled?

I'm setting up an environment for WordPress on apache2, on a fresh install of Ubuntu 12.04. In order to get friendly URLs working, I'm trying to set up mod_rewrite. I followed some instructions I ...
user124130's user avatar
20 votes
3 answers
855 views

Suspicious .htaccess File

This was uploaded to one of my FTP folders. I'm not familiar with Apache, but still curious - can someone tell me what type of dastardly act this file is trying to commit? Thanks! RewriteEngine On ...
ovinophile's user avatar
18 votes
3 answers
63k views

Returning "200 OK" in Apache on HTTP OPTIONS requests

I'm attempting to implement cross-domain HTTP access control without touching any code. I've got my Apache(2) server returning the correct Access Control headers with this block: Header set Access-...
Mark McDonald's user avatar
17 votes
2 answers
102k views

Apache URL rewriting in reverse proxy

I'm deploying Apache in front of a Karaf-hosted application (Apache and Karaf are on separate servers). I want Apache to operate as a reverse proxy and also to hide part of the URL. The URL to get ...
Jeremy Gooch's user avatar
16 votes
3 answers
20k views

apache2.4 mod_rewrite exclude specific alias directroy/uri

I have the following setup on one of my vhosts: ...<VirtualHost *:80> ServerName cloud.domain.de ServerAdmin [email protected] ServerSignature Off Alias "/.well-known/acme-...
FleBeling's user avatar
  • 163
15 votes
4 answers
46k views

Controlling Nginx proxy target using a cookie?

I'm trying to convert a reverse proxy using an interesting Apache mod_rewrite setup to use Nginx instead (due to external concerns we are moving from Apache to Nginx, and most everything works fine ...
Guss's user avatar
  • 2,840
14 votes
2 answers
73k views

Apache rewrite multiple conditions

I have a website that's migrated from an old domain name (e.g. olddomain.com) to a new domain name (e.g. newdomain.com). For SEO reasons, I need to rewrite all website traffic to the primary new ...
gurun8's user avatar
  • 345
13 votes
3 answers
9k views

How can I redirect an entire site to a single page?

I'm in the process of shutting down a site, and have replaced the old site with a single "nobody home" page at the root level of the site. Now I need to set up some redirection, so that any ...
Jim Miller's user avatar
13 votes
3 answers
32k views

How can I enable mod_rewrite in apache on Ubuntu?

How do you enable mod_rewrite with Apache in Ubuntu 10.04? I tried copying rewrite.load from /etc/apache2/mods-available to etc/apache2/mods-enabled but that didn't work.
Nathan Osman's user avatar
  • 2,745
13 votes
2 answers
30k views

Why is enabling the rewrite log in .htaccess not working?

I want to enable rewrite logging so that I can debug a rewrite rule but adding the RewriteLog directives is causing a 500 error. Version information: Ubuntu 14.04 Server version: Apache/2.4.12 (...
codecowboy's user avatar
  • 1,367
13 votes
1 answer
20k views

Can Apache conditionally perform a rewrite from a custom http header?

I have an apache server behind a (simple amazon) load balancer. I want to redirect any incoming traffic that is not 443 to 443. I would prefer it to use just one apache virtual host. So I'm trying ...
Lance Rushing's user avatar
13 votes
2 answers
12k views

Apache mod_proxy vs mod_rewrite

What is the difference between using mod_proxy and mod_rewrite? I have a requirement to send certain url patterns through the tomcat, which runs on the same host but under port 8080. I know this is ...
Scott Klarenbach's user avatar
13 votes
4 answers
12k views

Rewritten URLs with parameter length > 255 don't work

I'm using mod_rewrite to rewrite URLs like this: http://example.com/1,2,3,4/foo/ By doing this in .htaccess: RewriteEngine On RewriteRule ^([\d,]+)/foo/$ /foo.php?id=$1 [L,QSA] It works fine, ...
philfreo's user avatar
  • 997
13 votes
1 answer
7k views

Apache mod_rewrite double encodes query string on redirect

We've encountered a strange issue (a bug, perhaps?) with Apache mod_rewrite's behavior when passing through query strings. To reproduce, we've set up a clean Ubuntu (oneiric) install with the default ...
Erik Hesselink's user avatar
12 votes
3 answers
9k views

Difference between "Redirect permanent" vs. mod_rewrite RewriteRule

This is an Apache httpd 2.2 server. We require that access to this webserver be encrypted by HTTPS. When web clients visit my site at http://www.example.org/$foo (port 80), I want to redirect their ...
Stefan Lasiewski's user avatar
12 votes
6 answers
60k views

Why is https not working?

I am trying to redirect just the root of my site to https. Although the rewrite happens, https does not yield anything. The browser says. connecting to thinkingmonkey.me... and stagnates. ...
ThinkingMonkey's user avatar
12 votes
1 answer
63k views

What is the difference between HTTP_HOST and HTTPS_HOST in apache .htaccess files?

I'm editing an .htaccess file.. In RewriteCondition for RewriteRules, HTTPS_HOST seems to only match urls that are accessed via https:// protocol (ssl). I saw in docs somewhere that it's a T/F ...
SherylHohman's user avatar
12 votes
1 answer
16k views

max length of url 257 characters for mod_rewrite?

My url scheme is /foo/var1-var2-var3.../bar I am using these mod_rewrite rules: RewriteBase /foo/ RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d ...
Daniel's user avatar
  • 125
10 votes
4 answers
21k views

Why do .htaccess redirects work in http but not with https?

I have a simple .htaccess file that works great on the http version of the site but not when I go to https. Why? RewriteEngine on #This is so if the file exists then use the file RewriteCond %{...
Sheldon McGee's user avatar
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,945
10 votes
3 answers
8k views

mod_rewrite does not forward GET parameters

I'm having trouble setting up Apache with mod_rewrite on my development machine. Mod_rewrite is active, and works well for some rules. Some rules do not work as intended, like this one: RewriteRule ^...
Vegard Larsen's user avatar
10 votes
1 answer
58k views

How to pass a request from one apache server to another

I have two Apache Servers with mod_proxy enabled. I want to know how to "pass the request" from "Apache Server A" to "Apache Server B" using the same port (80). In server ...
maxtorzito's user avatar
10 votes
3 answers
12k views

Understanding apache 2.4 mod_proxy_fcgi and RewriteRules in htaccess

We've recently switched one of our web servers to apache 2.4 and running PHP via php-fpm and mod_proxy_fcgi. Most everything works quite well, but there is one problem that I don't understand yet. One ...
Konrad Neuwirth's user avatar
10 votes
2 answers
14k views

How do I make all URLs run through a single PHP file?

How do MVC systems where the urls are in these forms force all the requests through a single index.php file? http://www.example.com/foo/bar/baz http://www.example.com/goo/car/caz/SEO-friendly-name-of-...
jmucchiello's user avatar
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,646
10 votes
2 answers
20k views

Redirecting SSL without raising an alert

A client has an SSL certificate only for the www.site.com version of the domain, not site.com. Redirecting for regular HTTP was not a problem via mod_rewrite. However, this method seemed to fail for ...
djdy's user avatar
  • 583
10 votes
4 answers
6k views

mod_rewrite REQUEST_FILENAME doesn't contain absolute path

I have a problem with a file test operation in a mod_rewrite RewriteCond entry which is testing whether %{REQUEST_FILENAME} exists. It seems that rather than %{REQUEST_FILENAME} being an absolute path,...
Paul Dixon's user avatar
  • 1,576
9 votes
2 answers
883 views

Can't figure out a htaccess rule

I have this in my htaccess but can't figure out what its for. Because of the nature of rule, searching doesn't help either. RewriteCond %{REQUEST_URI} !(/$|\.) RewriteRule (.*) %{REQUEST_URI}/ [R=301]...
Richard1984's user avatar
9 votes
1 answer
20k views

Why does my RewriteLog not work?

I have an .htaccess which looks like this: RewriteEngine on RewriteLog "/Applications/MAMP/logs/rewrite_engine_log" RewriteCond %{REQUEST_URI} !/(index.php|css|images|js)/.*$ RewriteRule (.*) /...
openfrog's user avatar
  • 235
9 votes
2 answers
11k views

Force HTTPS with mod_rewrite, including proxied SSL

I've got a server getting some traffic from an SSL terminating load balancer- in which case it comes in as HTTP over port 80 with a http_x_forwarded_proto = "https" I want a mod_rewrite rule that ...
Yarin's user avatar
  • 1,376
9 votes
2 answers
31k views

How can I redirect any ServerAlias to the respective ServerName?

I want to 301 redirect all example.org to www.example.org. The following example is doing just that, but it's got a lot of noise to it and is thus hard to maintain and error prone: <VirtualHost ...
user569825's user avatar
9 votes
1 answer
54k views

SSL setup with apache in front of tomcat

i m trying to setup Apache with SSl and proxy SSL requests to my tomcat instance. I think i made the SSL work but theres still a error that shows up: Bad Gateway The proxy server received an invalid ...
SaifDeen's user avatar
  • 193
9 votes
6 answers
32k views

apache server-status not found. check if mod_status is enabled

I've enabled the apache_ plugins on a munin node: ln -sv /usr/share/munin/plugins/apache_* /etc/munin/plugins/ After restarting the node with service munin-node restart here are the errors I'm ...
Max's user avatar
  • 3,583
9 votes
4 answers
9k views

Why do I get a double trailing slash depending on where my RewriteRule is located?

I am using the following code to direct all www requests to non-www URLs: RewriteEngine On RewriteCond %{HTTP_HOST} ^www\.example\.org$ [NC] RewriteRule ^(.*)$ http://example.com/$1 [R=301,L] This ...
davekaro's user avatar
  • 193
9 votes
1 answer
3k views

HSTS and double redirect

I manage a little website in a shared hosting LAMP environment: this basically means the only thing I can edit is an htaccess file. I wanted to add HSTS support (and I did it), but, when I tested my ...
user avatar
9 votes
11 answers
2k views

.htaccess doesn't redirect to www-prefixed page properly

I'm trying to redirect an url without www. to www.version (example.com to www.example.com). I use the usual RewriteCond %{HTTP_HOST} ^example\.com [nc] RewriteRule (.*) http://www.example.com/$1 [R=...
cypher's user avatar
  • 91
8 votes
1 answer
247 views

Create VHost & Forward subdomain to it

Gurus of So I have a simple .htaccess file where I only redirect non www to www for my webapp. Now what I want to do is Create a new vhost like http://subdomain.mydomain.tld Create a redirect for ...
user avatar
8 votes
2 answers
9k views

Apache RewriteRule and slashes (%2F)

I have the following RewriteRule: RewriteRule ^like/(.+)$ ask.php/$1 Which works just fine for requests like: /like/someting+here/something+else But for requests where one of the path parts ...
Felix's user avatar
  • 380
8 votes
2 answers
9k views

Is there a limit for .htaccess?

Hey all. I was just wondering if there's a limit for the .htaccess file for Apache 2. I'm working on a caching plugin and thaught that it might be a good idea to use the .htaccess file to point to ...
kovshenin's user avatar
8 votes
2 answers
48k views

Online mod_rewrite testing tool

mod_rewrite statements can be hard to write and debug, therefore I need a lightweight online tool that enables me to test my RewriteCond, RewriteRule statements on the fly. Any such tool?
Graviton's user avatar
  • 2,945
8 votes
1 answer
34k views

Turn off 302 redirect and automatically redirect

I am testing redirects using curl on my localhost. When I run this command: $curl "test.test.com/landing/0192" I get this output: <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <html&...
Spencer's user avatar
  • 231
8 votes
1 answer
8k views

How to enable mod_rewrite detailed logging

I'm trying to enable mod_rewrite detailed logging at the trace3 log level, as described in man. I've put this line in my conf: LogLevel alert rewrite:trace3 However I'm getting this error: ...
user139980's user avatar
7 votes
5 answers
7k views

Relative substitution in mod_rewrite RewriteRule

I want to create a mod_rewrite RewriteRule which is independent from the location where the web page is installed. I want to define the rewrite rule in a .htaccess file. Let's take this as an example: ...
kayahr's user avatar
  • 303
7 votes
5 answers
14k views

Apache Redirect folder to subdomain

A client had an application at www.example.com/dir. They have now set up a subdomain at dir.example.com. The subdomain references the files stored at www.example.com/dir. They'd now like people ...
Thody's user avatar
  • 183
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
7 votes
3 answers
15k views

In Apache does the .htaccess file override the httpd.conf for mod_rewrites?

In my Apache httpd.conf file I have this declaration inside a VirtualHost tag. RewriteEngine On RewriteCond %{HTTP_HOST} !^www.shanestillwell.com$ [NC] RewriteRule ^(.*)$ http://www.shanestillwell....
Shane Stillwell's user avatar

1
2 3 4 5
45