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

.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/

    -

图片转代码服务由CSDN问答提供 功能建议

我遇到问题.htacess将URL重定向到子文件夹(子目录)。 我的文件夹结构就像 。 我的根文件夹web和sales中有两个目录。

Root

目录1 - web / 4.5, 目录2 - sales / 2.5

我的主要网址就像 http://beta.example。 com

当用户点击根网址( http://beta.example.com )时,它应该重定向到子文件夹名称 web / 4.5 这个我写的代码,它正在工作。代码就像。

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

以上代码正常运行,但是当用户点击根网址时<\ strong> http://beta.example.com/sales/ )它应该重定向到子文件夹 sales / 2.5 这个我写的代码,它没有工作。代码就像。

  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 
   
 
 <  p>  
 
 

它不起作用,它转到 web / 4.5 / sales / 2.5 / ,实际上它转到 /sales/2.5/ < / strong>

    -
  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

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.

    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题