开发者

HTACCESS: Change domain root to sub-directory

开发者 https://www.devze.com 2023-03-05 07:51 出处:网络
I\'m trying to use a sub-directory as the root folder for one of my domains. Using .htaccess, I use mod_rewrite\'s to get the job done. Here\'s the code I already have:

I'm trying to use a sub-directory as the root folder for one of my domains. Using .htaccess, I use mod_rewrite's to get the job done. Here's the code I already have:

RewriteCond %{HTTP_HOST} ^(www.)?domain.com$
RewriteCond %{REQUEST_URI} !^/domain/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /domain/$1

RewriteCond %{HTTP_HOST} ^(www.)?domain.com$
RewriteRule ^(/)?$ /domain/index.php [L]

This gets the job done, but not entirely. For example:

If I goto http://domain.com/, it displays index.php from inside the domain folder. If I goto http://domain.com/test/, it will display the contents (or 403) of the test folder. BUT if I goto http://domain.com/test (for use of shortcuts, or even to display the folder) I get redirected to http://domain.com/domain/test/.

That is not supposed to happen. If anything, it either does a mask from the .htaccess (if test is being used) or should just goto http://domain.com/test/. I have tried to figure out a way around this, and I ca开发者_如何转开发nnot. So I am seeking your help! :)

Any and all help is greatly appreciated.


Try this: its a little crude, but should do what you want. There is a little bit of confusion: some of what I've tried to do will depend on your RewriteBase (you might need to remove one or more / characters).

I've basically added an initial block that specifically looks for directories within your /domain/ folder that don't end with a trailing slash and added one. Let me know if it works at all.

RewriteCond %{HTTP_HOST} ^(www.)?domain.com$
RewriteCond %{REQUEST_URI} !^/domain/
RewriteCond /domain/%{REQUEST_URI} -d
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ /domain/$1/

RewriteCond %{HTTP_HOST} ^(www.)?domain.com$
RewriteCond %{REQUEST_URI} !^/domain/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /domain/$1

RewriteCond %{HTTP_HOST} ^(www.)?domain.com$
RewriteRule ^(/)?$ /domain/index.php [L]


The commenter is right, if you want to use a sub-directory as the root folder for one of my domains , just configure it in you apache virtual host configuration (DocumentRoot).


RewriteCond %{HTTP_HOST} ^(www.)?domain.com$
RewriteRule ^(.*)$ /domain/$1/ [L]

The above code successfully does everything I wanted it to do.


Use RewriteBase like this:

RewriteBase /f2f/f2fweb


What helped me is auto.htaccess generator on my host!!!!

DirectoryIndex index.php
RewriteEngine on
RewriteCond %{HTTP_REFERER} ^http://(www\.)?domain.com/TEST//.*$ [NC]
RewriteRule \.(js|css|jpg|gif|png|bmp|mp4|3gp|m4a|m4r|aac|mp3|ogg|wave)$ - [F]
0

精彩评论

暂无评论...
验证码 换一张
取 消