htaccess的重定向URL如果文件夹名称 [英] .htaccess redirect if folder name in url
问题描述
使用的.htaccess,我期待从一个文件夹的URL重定向到另一个。
using .htaccess, I'm looking to redirect a URL from one folder to another.
例如,如果用户要求forbiddenFolder http://www.mysite.com/forbiddenFolder/subfolder
For example, if a user requests 'forbiddenFolder' http://www.mysite.com/forbiddenFolder/subfolder
或
http://www.mysite.com/forbiddenFolder/somefile.php
或
http://www.mysite.com/forbiddenFolder/somefile.swf
或
http://www.mysite.com/forbiddenFolder/somefile.f4v
。
他们应该被重定向到 http://www.mysite.com/forbidden.php
我不想锁定目录本身,因为有所需资源那里。重定向应该唯一的工作基础上,URL字符串或者如果用户从创建一个从www.anothersite.com和水蛭文件的脚本http://www.mysite.com/forbiddenFolder
I don't want to lockdown the directory itself since there are resources there that are required. The redirect should only work based on the URL string OR if the user creates a script from www.anothersite.com and leeches files from http://www.mysite.com/forbiddenFolder
我相信的rewrite条件,应实行....?
I believe rewrite conditions should be implemented....?
推荐答案
您可以尝试这样的:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/forbiddenFolder [NC]
RewriteCond %{REQUEST_URI} /[\w]+\.(php|swf|f4v) [NC,OR]
RewriteCond %{REQUEST_URI} /[^.]+/?$ [NC]
RewriteCond %{REQUEST_URI} !forbidden\.php [NC]
RewriteRule .* /forbidden.php [L,NC]
在内部地图
http://www.mysite.com/forbiddenFolder/subfolder
或
http://www.mysite.com/forbiddenFolder/somefile.php
或
http://www.mysite.com/forbiddenFolder/somefile.swf
或
http://www.mysite.com/forbiddenFolder/somefile.f4v
要:
http://www.mysite.com/forbidden.php
有关永久性的,可见的重定向,替换 [L,NC]
与 [R = 301,L,NC]
For permanent and visible redirection, replace [L,NC]
with [R=301,L,NC]
通过修改后传入的URL结构。
With a modified incoming URL structure.
例如:
的http://localhost/trafficticket.tv/Sites/public_html/forbiddenFolder/somefile.swf
这一个替换的规则previous块:
Replace the previous block of rules with this one:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} /forbiddenFolder [NC]
RewriteCond %{REQUEST_URI} /[\w]+\.(php|swf|f4v) [NC,OR]
RewriteCond %{REQUEST_URI} /[^.]+/?$ [NC]
RewriteCond %{REQUEST_URI} !forbidden\.php [NC]
RewriteRule .* /trafficticket.tv/Sites/public_html/forbidden.php [L,NC]
要使用任何其他的URL,唯一的要求是,以prePEND正确的段路径 /forbidden.php
在重写规则。在这种情况下,该段是
To use any other URL, the only requirement is to prepend the correct segment path to /forbidden.php
in the rewrite rule. In this case, that segment is
/trafficticket.tv/Sites/public_html
但它可以是任何东西,或没事人一样在原来的问题。
but it could be anything or nothing, like in the original question.
这篇关于htaccess的重定向URL如果文件夹名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!