URL rewriting module for Apache web servers

learn more… | top users | synonyms (1)

138
votes
5answers
17k views

Redirect, Change URLs or Redirect HTTP to HTTPS in Apache - Everything You Ever Wanted How 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 ...
28
votes
4answers
67k 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 ...
19
votes
3answers
518 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 ...
9
votes
5answers
17k 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 ...
9
votes
2answers
4k 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 ...
9
votes
10answers
793 views

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

I'm trying to redirect an url without www. to www.version (domain.cz to www.domain.cz). I use the usual RewriteCond %{HTTP_HOST} ^domain\.cz [nc] RewriteRule (.*) http://www.domain.cz/$1 [R=301,L] ...
8
votes
1answer
182 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 ...
8
votes
2answers
9k 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?
7
votes
2answers
4k views

best way to debug nginx 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 ...
6
votes
3answers
13k 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.
6
votes
3answers
3k 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 request will be redirected to another machine. So is there an Apache log that shows clearly how ...
6
votes
4answers
845 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: ...
6
votes
2answers
5k 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 ...
6
votes
4answers
8k 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 ...
6
votes
4answers
3k 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 ...
6
votes
2answers
1k views

Apache mod_substitute on HTTP requests to reverse-proxied host

I have the following setup: Printer #1 on LAN Printer #2 on LAN Internet facing Debian Apache 2.2 web server at server-external-ip that I want to use as an IPP gateway to the two printers The two ...
6
votes
4answers
4k 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, ...
6
votes
1answer
3k 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 ...
6
votes
3answers
2k views

Using Mod_rewrite and Authentication on ALL incoming URLs

I have a need to make sure that my url, call it www.domain.com is always protected at least via Basic HTTP authentication. Also, I want to use mod_rewrite to send my users to one of two OC4j instances ...
6
votes
3answers
654 views

RewriteCond file-exists check fails for existing files

I have a weird scenario with this rewrite rule: RewriteCond img/$2/$3/$4/$1 -f RewriteRule ^img/(([a-z0-9]{4})([a-z0-9]{4})([a-z0-9]{4})[a-z0-9]{28}\.\w+)$ img/$2/$3/$4/$1 [L] The directory ...
5
votes
1answer
10k 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 (.*) ...
5
votes
2answers
2k 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 ...
5
votes
3answers
2k views

I need to rewrite https://domain.com => https://www.domain.com because of wildcard SSL

Like the subject says I need to rewrite https://domain.com => https://www.domain.com. But I have a wildcard SSL setup for the domain and the root domain does not match *.domain.com, thus the browser ...
5
votes
2answers
5k 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 ...
5
votes
1answer
1k 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 ...
5
votes
1answer
101 views

How to minimise effect of mischievous, persistent POST requests

For a few months now one of our shared hosting servers has been persistently and constantly hammered by "POST /" requests from what must be hundreds of thousands of individual IPs. On a number of ...
5
votes
1answer
1k views

Apache 2.4 with PHP-FPM .htaccess redirection

I have Apache 2.4 set up with PHP-FPM on a server. To pass from Apache to PHP-FPM I use the following: ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9001/hosting_files/site.com/admin_secure/$1 ...
4
votes
2answers
422 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 ...
4
votes
2answers
520 views

Forwarding 80 to 443 on Nagios woes

I perhaps just need some extra insight because I don't see where I'm going wrong. I used an SSL Cert to secure our nagios server. We want to specifically require all traffic over nagios (like 2 users, ...
4
votes
4answers
7k 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 ...
4
votes
1answer
122 views

Redirecting from one TLD to another

I have two domains for a website (we're using Apache), example.com and example.org. The website responds to a wildcard subdomain for both of these. I want, however, to have the .com as the canonical ...
4
votes
3answers
5k views

Apache2: 400 Bad Request with Rewrite Rules, nothing in error log?

This is driving me nuts. Background: I'm using the built-in Apache2 & PHP that comes with Mac OS X 10.6 I have a vhost setup as follows: NameVirtualHost *:81 <Directory ...
4
votes
4answers
1k views

Preventing vulnerability scripts from scanning apache server

Quick question for you all - fairly frequently in my httpd logs I see things like this: 66.11.122.194 - - [29/Jan/2010:11:06:44 +0000] "GET HTTP/1.1 HTTP/1.1" 400 418 "-" "Toata dragostea mea pentru ...
4
votes
2answers
3k 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 ...
4
votes
2answers
185 views

Can I make a simple calculation within a RewriteRule?

A change in how a site is structured means urls need changing from site/11-foo/21-bar to site/1-foo/1-bar i.e. I want to use a RewriteRule to subtract a constant (in this example, 10) from ...
4
votes
2answers
2k 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 ...
4
votes
2answers
12k views

Header set Access-Control-Allow-Origin not working with mod_rewrite + mod_jk

My first question on here on SF so please forgive me if I manage to bork the post. :) Anyways, I'm using mod_rewrite on one of my machines with a simple rule that redirects to a webapp on another ...
4
votes
2answers
3k views

Precedence of RewriteRules in .htaccess file on Apache Server

I have a number of RewriteRules in my .htaccess file. However, one specific rule is only executed if I remove another specific rule, regardless of how I order the two rules. Here's the rule which ...
4
votes
4answers
5k views

.htaccess not working (mod_rewrite)

Edit: I am pretty sure my .htaccess file is NOT being executed, and the problem is NOT with my rewrite rules. I have not having any luck getting my .htaccess with mod_rewrite working. Basically all ...
4
votes
1answer
2k 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: ...
4
votes
1answer
1k views

How do I reset Apache's RewriteCond directive?

I have some Apache configuration like this: # Image hotlinking rule RewriteCond %{HTTP_REFERER} ^http://badsite\.com/ RewriteRule .*/static/artwork/.*\.(jpg|png)$ /static/images/hotlink.png [L] # ...
4
votes
1answer
869 views

Forcing SSL in Apache without hard-coding the hostname

I think that I have this sorted (thanks mainly to the question How to redirect non-www to www without hardcoding using .htaccess?), but I still don't entirely understand a couple of things. I would ...
4
votes
2answers
230 views

Why does a $1 backreference work in a rewrite with no subgroups?

Someone I'm working with committed a RewriteRule such as the following to SVN: RewriteRule ^admin/ebay.*$ /yii.php/$1 [L] I warned him that it may not work because there is no subgroup in the match ...
4
votes
5answers
2k views

Apache mod_rewrite remove question mark (?) and query-string substitution

I registered a RewriteRule with mod_rewrite, but the substituted URL are wrong. The rule are: RewriteRule ^/img/z(0|1)u(.+)\.(gif|jpg|jpeg|png)$ /image-servlet/img/?z=$1&url=$2 ...
4
votes
1answer
2k views

how to rewrite '%25' in url

My website software replaces space characters with '+' characters in the URL, A proper link would look like 'http://www.schirmacher.de/display/INFO/How+to+reattach+a+disk+to+XenServer' for example. ...
4
votes
1answer
60 views

Methods for redirecting to a utility server

I have a situation where I need to facilitate file uploads of up to 200M to a utility server which is separate from the main web site server. Here's my configuration: Authenticated Client on Public ...
4
votes
1answer
458 views

Dynamic subdomains, mod_python and trac

I'm going to be running multiple subdomains, eventually too many to be able to each have their own config files. I have the vhosts working how I want them so each subdomain has their own folder eg ...
4
votes
1answer
3k views

htaccess redirect all to one file (except from localhost)

I want to redirect all traffic to a single .php gateway file, this file will do authentication and use ajax to pull the file that was requested. So I need a .htaccess with flow like this: if ...
4
votes
3answers
573 views

How do I create a custom header from an existing SSL environment variable?

OK I have spent all day on this-- I'm using apache with mod_ssl I'm trying to take an existing environment header, "%{SSL_CLIENT_S_DN_CN}s" which looks like "Lastname Firstname Mi username" and set a ...
4
votes
2answers
728 views

How do I set up URL Rewriting to a Heroku instance?

I'm more of an engineer than a devops guy, so please excuse me if this is extremely basic. My situation: I have a server on the example.edu network, so I don't control the main DNS interface to ...