CodeMoose
CodeMoose

Reputation: 3025

.htaccess - alias all www-only requests to subdirectory

Trying to install the wonderful Concrete5 CMS to use as my main site engine - the problem is it has about 15 different files and directories, and they clutter up my root. I'd really like to move it to a /_concrete/ subdirectory, and still maintain it in the domain root.

htaccess has never been my strong suit - after a lot of research and learning, and a lot of error 500s, my frustration is overriding my pride and I'm posting here. Here's exactly what I'm trying to accomplish:

Here's the closest I got with my htaccess, which produces an error 500:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !^_concrete
RewriteRule ^(.*)$ _concrete/$1 [L,QSA]

This is the result of 4 hours of sweat and blood (mostly blood), so I have to be close. I'm hoping one of your fine minds can point out a stupid mistake and put this thing to rest swiftly. Thanks for your time!


Addendum: I previously posted .htaccess - alias domain root to subfolder a while ago, which got me started. Please don't fall into the trap of thinking it's a duplicate.

Upvotes: 1

Views: 165

Answers (1)

Amine Hajyoussef
Amine Hajyoussef

Reputation: 4430

the problem is Internal Redirection loop, %{REQUEST_FILENAME} contains the Absolute system path of the file (/home/user/...) not the Url Path, your third condition states that the system path to the requested file starts with _concrete which will never be true.

to reproduce what happens, let's say for example a request is made to /contact (which is not a file) : the url pass all rewrite conditions and the request is being internally redirected to /_concrete/contact, now Mod_Rewrite will reexecute the htaccess again (L flag sto only the current run, if the url has been changed, rules will be applied again to the new url)

so, the new url /_concrete/contact will also pass all conditions and rewritten to /_concrete/_concrete/contact and so on ... which will produce a Redirection loop and Apache will output the 500 Error message

to solve this problem, you have to change your third condition with:

RewriteCond %{REQUEST_URI} !^/_concrete

Upvotes: 1

Related Questions