我们刚刚完成了一项重大的网站重组,我正在尝试编写一套不同特性的重定向规则。重定向是半工作的:
中指定的文本的URL。
ReWriteCond语句(当我希望看到浏览器中显示“未找到”错误消息时)。
.htaccess文件中的语句(位于网站根目录中)包括:
RewriteBase /
RewriteCond %{REQUEST_URI} /company/company-history.html
RewriteRule (.*)$ http://www.technofrolics.com/about/index.html
RewriteCond %{REQUEST_URI} /press
RewriteRule (.*)$ http://www.technofrolics.com/gallery/index.html
上面正确地执行所需的重定向,但当我在域名之后输入以下内容时,也会起作用:
/youcanenteranytext/hereatall/anditstillworks/press
换句话说,域后面和条件字符串之前的任何文本似乎都被允许/忽略。任何建议,如何限制条件或重写规则,以防止这将是非常感谢!
谢谢,玛格丽塔
发布于 2011-11-15 12:04:56
在尝试与%{REQUEST_URI}匹配时,需要在正则表达式中包含边界,^
表示匹配的开始。
RewriteCond %{REQUEST_URI} ^/company/company-history\.html
会使/garbage/stuff/comapny/company-history.html
的请求不匹配。同样:
RewriteCond %{REQUEST_URI} ^/press
会使/youcanenteranytext/hereatall/anditstillworks/press
的请求不匹配。您还可以在正则表达式中使用$
来指示匹配的结束,如下所示:
RewriteCond %{REQUEST_URI} ^/press$
是否只匹配/press
的请求,而不匹配/something/press
、/press/somethingelse
或/press/
的请求。
https://stackoverflow.com/questions/8142257
复制相似问题