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
8
votes
2 answers

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 generated static html files. So, anybody ever tried…
kovshenin
  • 11
  • 2
  • 6
7
votes
3 answers

Set header based on %{REQUEST_URI}

I am trying to set a header based on the URI of a particular page. I access a page using chrome. Inspect element and see that my URI header is giving the value /bst/index.html Now in my Apache config , I want to set a Header to Yes if my…
Jason Stanley
  • 91
  • 1
  • 1
  • 4
7
votes
5 answers

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 accessing www.example.com/dir to be redirected to…
Thody
  • 183
  • 3
  • 3
  • 5
7
votes
3 answers

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 structure for this is (simplified): var/ images/ .. …
deceze
  • 483
  • 1
  • 6
  • 20
7
votes
3 answers

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 running on my server. I also want to protect my…
El Guapo
  • 171
  • 1
  • 3
7
votes
2 answers

apache url / filename with special characters

I have this url: http://domain.com/wp-content/uploads/2012/10/Hvilke-vilkår-følger-med-når-du-bestiller-nyt-bredbånd.png If I ftp/ssh or just browse to that folder (apache index feature), I see the…
user145705
7
votes
3 answers

404 Error on a file that exists?

A script makes a GET request to my URL like so: http://mydomain.com/cgi-bin/uu_ini_status_audios.pl?tmp_sid=b742be1d131c4d32237a9f1fcdca659e&rnd_id=0.2363453360320319 However, I get a 404 returned straight away: The requested URL…
Abs
  • 1,559
  • 5
  • 19
  • 32
7
votes
3 answers

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.com/$1 [L,R=301] And this inside my…
Shane Stillwell
  • 337
  • 1
  • 4
  • 11
7
votes
2 answers

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 %{REQUEST_FILENAME} !-f RewriteCond…
0xdeadbeef
  • 397
  • 6
  • 13
6
votes
1 answer

Virtual host not working AWS apache

I have following virtual host ( in apache2.conf file ) to load all subdomain from a single directory on AWS DocumentRoot /var/www/html ServerName mydevsite.com ServerAlias mydevsite.com
Vikram
  • 167
  • 2
  • 10
6
votes
2 answers

Redirect all urls to the root except /wp-admin and wp-json

I try to redirect all urls to the root except for the wordpress administration and the wordpress REST API. I have these rules in my .htaccess: RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond…
Quentin Brosse
  • 63
  • 1
  • 1
  • 4
6
votes
1 answer

Apache's mod_rewrite and PHP's REQUEST_URI variable

I have an issue with Apache passing to the PHP $_SERVER['REQUEST_URI'] variable the URL after it has been rewritten rather than the original one requested. I am doing this rewriting because I had a WordPress website and wanted to move it to a…
Mg512
  • 61
  • 1
  • 3
6
votes
1 answer

ProxyPass only if file doesn't exist

I've seen this example: RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f RewriteRule ^/(.*)$ balancer://app_cluster%{REQUEST_URI} [P,QSA,L] I need a similar thing that will delegate to mod_proxy (i.e. do a ProxyPass) when a static file does not…
kaqqao
  • 163
  • 1
  • 5
6
votes
1 answer

Masking the URL in a mod_rewrite

Is there any way of doing a mod_rewrite from one domain to another, but keeping the browser URL the same throughout? This is what I want: User enters something like bacon.com and ends up on example.com/bacon, but the browser URL always stays as…
hohner
  • 213
  • 2
  • 3
  • 7
6
votes
2 answers

RedirectMatch and Query String

Compare these two RedirectMatch's. The first doesn't work: RedirectMatch 302 ^/redirect\.php[?]page=(.+)$ http://somewhereelse.com/$1 Versus this, which will redirect to http://somewhereelse.com/?page=wherever: RedirectMatch 302…
pinate
  • 207
  • 1
  • 3
  • 9