Apache Mod_Rewrite Htaccess for dynamic URL

I have this link

www.example.com/1/title

which goes on

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]

Ok, but now, how to make sure that if someone types on www.example.com/post.php?author=1&title=title redirects to www.example.com/1/title

I spent literally hours online researching this, but the information is obscure (at least for me) and does not work.

2 things still betray me:

  • Writing a pretty url in dynamic and then dynamic in pretty - Doesn't the loop create?
  • 301, , . 301 , () RewriteRule.

, () $1 $2... . :

RewriteRule ^post.php?author=([0-9]+)&title=([\w-_:]+)$ post/$1/$2

, , . , http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html, ( ) , . , ?

,

+4
1

:

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]
+1

Source: https://habr.com/ru/post/1526268/


All Articles