Questions tagged [mod-rewrite]

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

For an introduction and examples of using mod_rewrite, read over the comprehensive article,
"Everything You Ever Wanted to Know about Mod_Rewrite Rules but Were Afraid to Ask"

2224 questions
9
votes
1 answer

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 website here for HSTS preload eligibility, I got…
user487101
9
votes
4 answers

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, I'm getting a path which is rooted at the…
Paul Dixon
  • 1,516
  • 3
  • 23
  • 37
9
votes
1 answer

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 A" with internal ip: 192.168.0.5 I have configured DNS and I am also using it…
maxtorzito
  • 223
  • 1
  • 3
  • 6
9
votes
1 answer

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 response from an upstream server. * SSL…
SaifDeen
  • 193
  • 1
  • 1
  • 5
9
votes
2 answers

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-the-object http://www.example.com/hey/you EDIT:…
jmucchiello
  • 215
  • 1
  • 2
  • 6
9
votes
2 answers

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 only allows direct HTTPS traffic or forwarded HTTPS…
Yarin
  • 1,366
  • 8
  • 19
  • 31
9
votes
6 answers

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 getting: $ munin-node-configure --suggest 2>/dev/null |…
Max
  • 3,523
  • 16
  • 53
  • 71
9
votes
11 answers

.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=301,L] This works on all my other projects.…
cypher
  • 91
  • 4
9
votes
2 answers

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: ServerName example.org …
user569825
  • 351
  • 3
  • 6
  • 12
9
votes
4 answers

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 works great inside an .htaccess file in the root of…
davekaro
  • 193
  • 1
  • 3
8
votes
2 answers

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
  • 2,865
  • 12
  • 42
  • 64
8
votes
1 answer

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: Syntax error on line 6 of…
user139980
  • 81
  • 1
  • 2
8
votes
1 answer

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 anybody coming to that subdomain to a folder on my…
iUsable
8
votes
5 answers

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: RewriteEngine on RewriteRule ^(.*)\.html…
kayahr
  • 313
  • 4
  • 14
8
votes
2 answers

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 contains an escaped slash (%2F), the server spits out a…
Felix
  • 380
  • 3
  • 11