Forum Moderators: phranque

Message Too Old, No Replies

use .htaccess for documentRoot

         

JesseB

4:33 pm on Jan 20, 2012 (gmt 0)

10+ Year Member



I am in a cPanel environment where I can't access the httpd.conf file to change the documentRoot, and am trying to use mod rewrite to accomplish the same thing in the .htaccess file.

I am using a cms and want to use the static version of the site as a backup that I can switch to easily in case of cms failure.

I would keep the static site in a directory
www.mydomain.com/static

but would want the urls to not show the "/static" part to the user.
it would just display as www.mydomain.com/filename.htm instead of www.mydomain.com/static/filename.htm

I have a redirect working as
RewriteEngine on
RewriteRule ^/$ /static/ [R]

but this displays "/static" in the url which I wish to avoid.
I have been searching the documentation, but find the syntax for redirect rules to be confusing.

lucy24

9:18 pm on Jan 20, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Look up the two words "redirect" and "rewrite" together. You will be doing both. You will also need to get a grip on the basic differences in syntax between mod_alias (Redirect by that name) and mod_rewrite (can also Redirect). Your current rule uses mod_alias syntax to create a 302 Redirect of the index page. The 302 in this case may really be what you want, but the syntax won't work.

Come to think of it, you may not need to redirect at all. Optimally your users will always see the same URLs, no matter where the content is coming from.

g1smd

12:04 am on Jan 21, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Use a RewriteRule that accepts URLs requests and fetches the same path but with /static/ prepended. Use the [L] flag, not the [R] flag.

Add a preceding RewriteCond looking at REQUEST_URI testing for NOT /static to prevent a rewrite loop.

Do not include /static in any of the links on the site.