Kit
Kit

Reputation: 4105

Htaccess Rewrite Condition Issue

I am trying to follow Paul Irish's example of how to have a built minified version of my site inside /publish. I have successfully integrated the automated build process but can't get the .htaccess file to point to the correct folder.

My Aim:

When on live server to redirect all normal site traffic to the /publish folder to use the 'built' site. But when on the development server to use the development files in the / normal root folder.

My Problem:

I want the htaccess to rewrite requests from the root to the /publish directory. As the same htaccess be will used inside the / and /publish directory I need a rewrite condition to stop it rewriting requests inside the /publish directory to /publish/publish/my-page. I have this at present:

RewriteCond %{SCRIPT_FILENAME} !^/publish/.+
RewriteRule ^(.*)$ publish/$1 [L]

The condition above looks for requests that do not have the script_filename starting with /publish. If so it should rewrite the request with publish/ in front.

However, this is not working. Does anyone have any ideas what is wrong with it? Could I use different server variables to identify if the request is in the /publish directory or not.

Upvotes: 1

Views: 1094

Answers (2)

LazyOne
LazyOne

Reputation: 165471

You should use %{REQUEST_URI} instead as it is the correct variable that will have path relative to the site root and not physical file name like others.

RewriteCond %{REQUEST_URI} !^/publish/
RewriteRule ^(.*)$ publish/$1 [L]

Upvotes: 2

psycho
psycho

Reputation: 632

I think %{SCRIPT_FILENAME} isn't set when you don't explicitely ask Apache a php file, maybe you should try with %{REQUEST_FILENAME} instead.
By the way, you can have a look on mod_rewrite doc page for more informations : http://httpd.apache.org/docs/current/en/mod/mod_rewrite.html#rewritecond

Upvotes: 2

Related Questions