使用 htaccess、多个参数重写 URL
Rewriting URLs with htaccess, multiple parameters
我正在尝试重写这样的东西:
https://mywebsite.com/pages/article.html?id=1&title=Title-Goes-Here
进入
https://mywebsite.com/pages/article/1/Title-Goes-Here
使用此重写规则
RewriteEngine on
RewriteRule ^article/([0-9]+)/([0-9a-zA-Z_-]+)$ article.html?id=&title= [NC,L]
但是,当我在 https://htaccess.madewithlove.com/ 中尝试此代码时,它给了我
This rule was not met.
也在我的网站htaccess文件上试过了,没有结果。不知道哪里出了问题
请不要在在线网站上创建或测试规则,它们不值得信任,因此请在您的本地主机或 apache 中测试这些规则。
根据您显示的 samples/attempts,请尝试遵循 htaccess 规则。考虑到您在浏览器中点击 URL https://mywebsite.com/pages/article.html?id=1&title=Title-Goes-Here
并且您想将其重定向到浏览器中的 URL https://mywebsite.com/pages/article/1/Title-Goes-Here
。
请确保在测试您的 URL 之前清除您的浏览器缓存。
RewriteEngine ON
##External redirect in browser rules here....
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{THE_REQUEST} \s/([^/]*)/([^.]*)\.html\?id=([^&]*)&title=(\S+)\s [NC]
RewriteRule ^ /%1/%2/%3/%4? [R=301,L]
##Internal rewrite to html file rules here....
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/([^/]*)/([^/]*)/([^/]*)/?$ /.html?id=&title= [QSA,NC,L]
我正在尝试重写这样的东西:
https://mywebsite.com/pages/article.html?id=1&title=Title-Goes-Here
进入
https://mywebsite.com/pages/article/1/Title-Goes-Here
使用此重写规则
RewriteEngine on
RewriteRule ^article/([0-9]+)/([0-9a-zA-Z_-]+)$ article.html?id=&title= [NC,L]
但是,当我在 https://htaccess.madewithlove.com/ 中尝试此代码时,它给了我
This rule was not met.
也在我的网站htaccess文件上试过了,没有结果。不知道哪里出了问题
请不要在在线网站上创建或测试规则,它们不值得信任,因此请在您的本地主机或 apache 中测试这些规则。
根据您显示的 samples/attempts,请尝试遵循 htaccess 规则。考虑到您在浏览器中点击 URL https://mywebsite.com/pages/article.html?id=1&title=Title-Goes-Here
并且您想将其重定向到浏览器中的 URL https://mywebsite.com/pages/article/1/Title-Goes-Here
。
请确保在测试您的 URL 之前清除您的浏览器缓存。
RewriteEngine ON
##External redirect in browser rules here....
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{THE_REQUEST} \s/([^/]*)/([^.]*)\.html\?id=([^&]*)&title=(\S+)\s [NC]
RewriteRule ^ /%1/%2/%3/%4? [R=301,L]
##Internal rewrite to html file rules here....
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/([^/]*)/([^/]*)/([^/]*)/?$ /.html?id=&title= [QSA,NC,L]