Brian
Brian

Reputation: 7135

.htacces rewrite condition not hitting?

Lets say I have a two websites www.sample.com and files.sample.com.

In an .htaccess file within the webroot of www.sample.com, I have the following:

<IfModule mod_rewrite.c>
  RewriteEngine on

  RewriteCond %{QUERY_STRING} ^files\/uploads [NC]
  RewriteRule ^(.*)$ http://files.website.com/$1 [NC,L]
</IfModule>

The desired result is to have all requests of www.sample.com/files/uploads/file.xml or www.sample.com/files/uploads/subfolder/file.json get 302 redirected to files.sample.com/files/uploads/file.xml and www.sample.com/files/uploads/subfolder/file.json, respectively.

However, I can't get the rule to fire. The directory "files" does not exist on the www.sample.com website at all.

Could anyone give me a little help as to why the

Upvotes: 1

Views: 103

Answers (2)

jmlsteele
jmlsteele

Reputation: 1239

You probably want REQUEST_URI not QUERY_STRING.

RewriteCond %{REQUEST_URI} ^/files\/uploads [NC]

Also note the leading slash.

Upvotes: 2

Andrey Nikishaev
Andrey Nikishaev

Reputation: 3882

Did you turn on mod_rewrite in your apache config? Also yor change '^files/uploads' to ^/files/uploads and QUERY_STRING to PATH_INFO. QUERY_STRING - this is all data after '?' character.

Upvotes: 0

Related Questions