I have this link
www.example.com/1/title
which goes to
www.example.com/post.php?author=1&title=title
because of this rule
RewriteRule ^post/([0-9]+)/([\w-_:]+)/?$ post.php?author=$1&title=$2 [L,QSA,NC]
Fine, but now how do make it such that if somebody types in www.example.com/post.php?author=1&title=title to redirect to www.example.com/1/title
I have spent literally hours online researching this but the information is vague (at least for me) and not working.
2 things stump me so far:
I understand that (groups) can later be accessed by using $1 and $2... but when trying the reverse I cannot make it work. Eg:
RewriteRule ^post.php?author=([0-9]+)&title=([\w-_:]+)$ post/$1/$2
But like I said nothing works. I've been beating my head on sites like http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html but I cannot fully understand (or apply) what I'm reading there. Can you please let me know what I'm doing wrong or how I should approach this problem?
Many thanks for any help you can give me
You need a new rule like this:
RewriteCond %{THE_REQUEST} \s/+post\.php\?author=([^&]*)&title=([^\s&]+) [NC]
RewriteRule ^ post/%1/%2? [R=302,L]
RewriteRule ^post/([0-9]+)/([\w-_:]+)/?$ post.php?author=$1&title=$2 [L,QSA,NC]
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.