.htaccess 重定向与我无法删除的另一个 htaccess 规则冲突
信息:
所以我对 .htaccess 相当陌生,并且已经阅读了一些内容。
基本上我想这样做,将网址 www.example.com/center-pro 重定向到 www.example.com/pro-hq (在这里找到了.htaccess URL重定向)
但是我正在工作的网站已经有一个.htaccess文件就位。
这就是我要添加的内容:
Options +FollowSymLinks #already in htaccess file
RewriteEngine On #already in htaccess file
Redirect 301 /center-pro http://www.example.com/pro-hq #line I added
RewriteCond %{REQUEST_FILENAME} !-f #already in htaccess file
RewriteCond %{REQUEST_FILENAME} !-d #already in htaccess file
RewriteRule ^(.*) index.php?idstring=$1&%{QUERY_STRING} #already in htaccess file
最后一行似乎弄乱了我的重定向
所以我的重定向的输出如下所示: www.example.com/pro-hq?idstring=center-pro
问题:
有没有办法让上面的重定向规则保持当前的 .htaccees 这样我不要搞乱当前的站点设置。
** 注意:执行 RewriteRule 是可行的,但我想使用重定向,这样人们就不会共享错误的网址。
The Information:
So I am fairly new to .htaccess and have being reading a bit.
Basically I want to do this, redirect the url www.example.com/center-pro to www.example.com/pro-hq
(found how here here .htaccess URL redirect)
However the site i am work on already has a .htaccess file in place.
This is what I am adding doing :
Options +FollowSymLinks #already in htaccess file
RewriteEngine On #already in htaccess file
Redirect 301 /center-pro http://www.example.com/pro-hq #line I added
RewriteCond %{REQUEST_FILENAME} !-f #already in htaccess file
RewriteCond %{REQUEST_FILENAME} !-d #already in htaccess file
RewriteRule ^(.*) index.php?idstring=$1&%{QUERY_STRING} #already in htaccess file
The last line seems to be messing with my redirect
So the output from my redirect looks like this :
www.example.com/pro-hq?idstring=center-pro
The Question:
Is there any way to have the redirect rule above and keep the current .htaccees so I don't mess up the current site settings.
** note: Doing a RewriteRule works but i would like to use a redirect so people don't share the wrong url.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您也可以使用
mod_rewrite
进行外部重定向:这可能是最简单的解决方案,代替当前的
Redirect
。问题在于mod_rewrite
在mod_alias
之前执行其工作,虽然重写的 URI 路径没有传递,但不幸的是修改后的查询字符串却传递了。您还可以调整您的RewriteRule
以防止它处理您想要由mod_alias
处理的路径,但我更喜欢第一个选项:此外,对于您当前的
RewriteRule< /code>,您只需使用
QSA
标志,而不是手动将查询字符串附加到 URL:You can use
mod_rewrite
for your external redirection too:This is probably the simplest solution, in place of your current
Redirect
. The problem is thatmod_rewrite
performs its work beforemod_alias
, and while the rewritten URI path is not passed along, the modified query string unfortunately is. You could also condition yourRewriteRule
to prevent it from processing the path you want handled bymod_alias
, but I prefer the first option:Additionally, for your current
RewriteRule
, you can just use theQSA
flag instead of manually appending the query string to the URL: