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.

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

报告相同问题?

悬赏问题

  • ¥15 MPLS/VPN实验中MPLS的配置问题
  • ¥15 materialstudio氢键计算问题
  • ¥15 已知隐函数其中一个变量的,求另外一个变量
  • ¥15 echarts图表制作
  • ¥15 halcon根据玻璃面板纹路取区域
  • ¥15 HFSS设计小型化180度耦合器
  • ¥15 使用CInternetSession,CHttpFile读取网页文件时有些电脑上会卡住怎么办?
  • ¥15 水下机器人的半物理仿真研究
  • ¥15 微服务假死,一段时间后自动恢复,如何排查处理
  • ¥50 webrtc-streamer TCP rtsp