.htaccess重定向到子文件夹 [英] .htaccess redirect to subfolders

查看:106
本文介绍了.htaccess重定向到子文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

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

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

我的主要URL网站就像 http://beta.example.com

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

当用户点击根URL( http://beta.example.com )时,它应该重定向到子文件夹名称 web/4.5 ,为此我编写了代码它正在工作.代码就像.

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

上面的代码有效,但是, 当用户点击根URL( http://beta.example.com/sales/)时,应重定向至子文件夹 sales/2.5 ,为此我编写了代码并它不起作用.代码就像.

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

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

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

    --

推荐答案

此处

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

[L]停止以下重定向过程.

The [L] stops following redirect processes.

这篇关于.htaccess重定向到子文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆