.htaccess 重定向与我无法删除的另一个 htaccess 规则冲突

发布于 2024-09-16 07:55:01 字数 1016 浏览 1 评论 0原文

信息:

所以我对 .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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

亣腦蒛氧 2024-09-23 07:55:01

您也可以使用 mod_rewrite 进行外部重定向:

RewriteRule ^center-pro$ http://www.example.com/pro-hq [R=301,L]

这可能是最简单的解决方案,代替当前的 Redirect。问题在于 mod_rewritemod_alias 之前执行其工作,虽然重写的 URI 路径没有传递,但不幸的是修改后的查询字符串却传递了。您还可以调整您的 RewriteRule 以防止它处理您想要由 mod_alias 处理的路径,但我更喜欢第一个选项:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond ${REQUEST_URI} !^/center-pro
RewriteRule ^(.*) index.php?idstring=$1&%{QUERY_STRING}

此外,对于您当前的RewriteRule< /code>,您只需使用 QSA 标志,而不是手动将查询字符串附加到 URL:

RewriteRule ^(.*) index.php?idstring=$1 [QSA]

You can use mod_rewrite for your external redirection too:

RewriteRule ^center-pro$ http://www.example.com/pro-hq [R=301,L]

This is probably the simplest solution, in place of your current Redirect. The problem is that mod_rewrite performs its work before mod_alias, and while the rewritten URI path is not passed along, the modified query string unfortunately is. You could also condition your RewriteRule to prevent it from processing the path you want handled by mod_alias, but I prefer the first option:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond ${REQUEST_URI} !^/center-pro
RewriteRule ^(.*) index.php?idstring=$1&%{QUERY_STRING}

Additionally, for your currentRewriteRule, you can just use the QSA flag instead of manually appending the query string to the URL:

RewriteRule ^(.*) index.php?idstring=$1 [QSA]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文