douzhuo5671 2014-04-17 06:40
浏览 117
已采纳

.htaccess重定向到子文件夹

i having problem with .htacess redirect URL's to sub-folders (sub-directory). My Folder Structure was like. i had two directories in my root folder web and sales.

Root

Directory 1 - web/4.5 , Directory 2 - sales/2.5

And my main URL site was like http ://beta.example.com

when user hits the root URL (http ://beta.example.com) it should redirect to sub-folder name web/4.5 for this i wrote code and it was working.the code was like.

RewriteEngine On

RewriteCond %{HTTP_HOST} ^beta.example\.com$
RewriteCond %{REQUEST_URI} !^/web/4.5
RewriteRule (.*) /web/4.5/$1

the above code was working but, when user hits the root URL (http ://beta.example.com/sales/) it should redirect to sub-folder sales/2.5 for this i wrote code and it was not working.the code was like.

RewriteEngine On

RewriteRule ^sales/(.*) sales/2.5/$1

RewriteCond %{HTTP_HOST} ^beta.example\.com$
RewriteCond %{REQUEST_URI} !^/web/4.5
RewriteRule (.*) /web/4.5/$1

it was not working ,it goes to web/4.5/sales/2.5/ ,actually it goes to /sales/2.5/

    -

  • 写回答

1条回答 默认 最新

  • dongyuan9109 2014-04-17 06:50
    关注

    Here

    RewriteEngine On
    
    RewriteCond %{REQUEST_URI} !^/sales/2.5
    RewriteRule ^sales/(.*) /sales/2.5/$1 [L]
    
    RewriteCond %{REQUEST_URI} !^/sales/2.5
    RewriteCond %{REQUEST_URI} !^/web/4.5
    RewriteRule (.*) /web/4.5/$1
    

    The [L] stops following redirect processes.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?