apache - htaccess 中的 url 参数问题

标签 apache .htaccess mod-rewrite url-rewriting friendly-url

RewriteRule ^/pages/topic\.php?tag=$1 /topics/([^/]+) [R=301,L]

RewriteRule ^topics/([^/]+)/?$  /pages/topic.php?tag=$1 [END]

我的问题在于 301 重定向,我相信问题在于 tag=$1/([^/]+) 我不完全确定我已经正确完成了此操作,我想要的结果是,当用户导航到 /pages/topic.php?tag=cryptocom 时,用户将被重定向到 /topics/cryptocom/ 感谢您的帮助。

最佳答案

根据您显示的尝试/示例,请尝试遵循 htaccess 规则文件。

在测试您的网址之前,请确保清除浏览器缓存。

RewriteEngine ON
##External redirect rules here.
RewriteCond %{THE_REQUEST} \s/pages/([^.]*)\.php\?tag=(\S+)\s
RewriteRule ^ /%1/%2? [R=301,L]

##Internal rewrite rules here...
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^topics/([^/]+)/?$  /pages/topic.php?tag=$1 [NC,QSA,L]

关于apache - htaccess 中的 url 参数问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70858118/

相关文章:

Apache 重写到其他目录(如果那里存在文件)

php - 使用 htaccess 的 CakePHP 子域

apache - 将所有静态文件放在 WAR/EAR 文件之外是一种好的做法吗?

.htaccess 强制 www。和特定域的 https

.htaccess 重定向 http ://with and without www and https://www to https://non-www

apache - htaccess mod 重写具有多个参数的同一 URL

regex - htaccess 将 https 重定向到另一个 https

java - 403 拒绝访问 tomcat 7.0.42

java - Apache HttpClient POST 上传文件不适用于 MultipartEntityBuilder 上传

php - 将运行用户从 nt authority\system 更改为 AD 用户 - Windows 上的 Apache