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

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 variable that indicates if the url was accessed using…
SherylHohman
  • 405
  • 1
  • 5
  • 15
12
votes
3 answers

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 request to the HTTPS encrypted website at…
Stefan Lasiewski
  • 23,667
  • 41
  • 132
  • 186
12
votes
1 answer

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 to detect that if the HTTP_X_FORWARDED_PORT…
Lance Rushing
  • 255
  • 2
  • 3
  • 6
12
votes
6 answers

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. Listen 80 & Listen 443 are present in the conf file. I…
ThinkingMonkey
  • 476
  • 1
  • 9
  • 18
12
votes
2 answers

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 something for mod_proxy, but I"m wondering why I…
Scott Klarenbach
  • 569
  • 2
  • 8
  • 20
12
votes
1 answer

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 RewriteRule ^ index.php [PT,L] If the length of the string…
Daniel
  • 125
  • 1
  • 1
  • 6
12
votes
3 answers

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 request to any part of the site, no matter how complicated,…
Jim Miller
  • 713
  • 2
  • 11
  • 23
10
votes
3 answers

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 ^static/([^/]+)/([^/]+) …
Vegard Larsen
  • 285
  • 4
  • 9
10
votes
3 answers

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

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] RewriteCond %{HTTP_COOKIE} its=me [NC] The last…
Nick
  • 4,503
  • 29
  • 69
  • 97
10
votes
3 answers

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 of our sites is running WordPress, which brings…
Konrad Neuwirth
  • 223
  • 1
  • 2
  • 6
10
votes
2 answers

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 us for HTTPS. We want to redirect https://site.com…
djdy
  • 583
  • 2
  • 4
  • 15
10
votes
4 answers

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 %{REQUEST_FILENAME} -f RewriteRule ^ %{REQUEST_FILENAME}…
Sheldon McGee
  • 441
  • 1
  • 7
  • 14
10
votes
3 answers

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 how the redirection takes place? Because the…
Graviton
  • 2,865
  • 12
  • 42
  • 64
9
votes
1 answer

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 (.*) /mysite/index.php/$1 When I add that RewriteLog…
openfrog
  • 235
  • 1
  • 4
  • 8
9
votes
2 answers

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] Can anyone please explain what its for?