[英]RewriteRule is working opposite or not working?
My default url is http://www.example.com/?page=20&id=2 and i want to show it as http://www.example.com/page/20/id/2/ with .htaccess 我的默认网址是http://www.example.com/?page=20&id=2 ,我希望将其显示为http://www.example.com/page/20/id/2/并使用.htaccess
I use the following codes; 我使用以下代码;
<IfModule mod_rewrite.c>
Options +FollowSymLinks +Indexes -MultiViews
RewriteEngine on
RewriteBase /
DirectoryIndex index.php
RewriteRule page/(.*)/id/(.*)/?$ ?page=$1&id=$2 [R=301,NE,NC,L]
RewriteRule page/(.*)/?$ ?page=$1 [R=301,NE,NC,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /
</IfModule>
If i remove [R=301,NE,NC,L] at the end of the codes, /page/20/id/2/ is working if i go directly but when i write as ?page=20&id=2, url is not changed on browser. 如果我在代码末尾删除[R = 301,NE,NC,L],/ page / 20 / id / 2 /正在工作,如果我直接去,但当我写为?page = 20&id = 2时,url是浏览器没有改变。
If i use as the above it redirect from /page/20/id/2/ to ?page=20&id=2 which is the opposite of what i try to do. 如果我使用如上,它从/ page / 20 / id / 2 /重定向到?page = 20&id = 2,这与我尝试做的相反。
i will appreciate if anyone can help me. 如果有人能帮助我,我将不胜感激。
Thanks. 谢谢。
this should work 这应该工作
RewriteEngine On
RewriteCond %{HTTP_HOST} example.com$ [NC]
RewriteCond %{QUERY_STRING} page=(.*)&id=(.*)
RewriteRule ^$ /page/%1/id/%2? [L,R=301]
htaccess fiddle http://htaccess.mwl.be?share=afb950c7-106e-5b9c-a7ed-358aed027bc0 htaccess小提琴http://htaccess.mwl.be?share=afb950c7-106e-5b9c-a7ed-358aed027bc0
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.