.htaccess RewriteRule 在浏览器中无需更改 URL

标签 .htaccess mod-rewrite

我有.htaccess文件:

Options +FollowSymlinks
RewriteEngine on
RewriteBase /

RewriteCond %{HTTP_HOST} ^somedomain.com [NC]
RewriteRule ^(.*)$ http://www.somedomain.com/$1 [R=301,NC]

RewriteRule ^r/(.*)$ index.php?rid=$1 [NC]

但是当我请求像 www.somedomain.com/r/123 这样的 URL 并显示像 www.somedomain.com/index.php?rid 这样的 URL 时,最后一个条件会在浏览器中执行重定向=123 。但我需要在不更改 URL 的情况下调用此脚本。

出了什么问题?

最佳答案

您使用了R=301尝试使用L,如下所示:

RewriteCond %{HTTP_HOST} ^somedomain.com [L]
RewriteRule ^(.*)$ http://www.somedomain.com/$1 [L]

RewriteRule ^r/(.*)$ index.php?rid=$1 [L]

关于.htaccess RewriteRule 在浏览器中无需更改 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13194043/

相关文章:

android - htaccess 针对代理的保护

apache - 将 301 从带有问号的 URL 重定向到新的 URL

php - htaccess 排除 CSS/JS/图像

.htaccess - 使用两个404页面未找到的页面来表示网站的不同语言版本

linux - 如何在不同的目录中包含相同的文件?

apache - 重写以附加到查询字符串

python - Apache mod_rewrite 与多个 Web 应用程序

Apache:url 中的 %25(400 错误请求)

apache - htaccess : How to redirect from old domain to new with folder condition

.htaccess - 多个 url 托管只有一个需要 https