I want to rewrite url from article.php?id=123 to article/123
I added the following rule, it works fine
RewriteRule ^article/(.*) /article.php?id=$1 [PT]
I also want to add a 301 redirect rule to let search engine know article.php?id=123 should move to article/123. I added the following rule but seems not working.
RewriteRule ^article.php?id=(.*)$ /article/$1 [R=301,L]
尝试这样:
RewriteRule ^article.php?id=(.*)$ /article/$1 [L,R=301]
You need to match against the actual request and not the URI because the URI gets rewritten by other rules:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /article\.php\?id=([^\ ]+)
RewriteRule ^article\.php$ /article/%1? [R=301,L]
If you don't match against the actual request, a redirect loop will occur:
/article.php?id=123
/article/123
/article/123
/article.php?id=123
/article/123
/article/123
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.