Redirection loop (URL rewriting)

75 Views Asked by At

I'm trying to rewrite my website URLs. I have:

http:// website.com/v2/message.php?ID2=123

I want:

http:// website.com/v2/message-123.php

I tried something in my htaccess but I've a redirection loop :'(

Here is my .htaccess:

RewriteCond %{QUERY_STRING} ^ID2=([0-9]+)$
RewriteRule message.php? http://website.com/v2/message-%1.php? [L,R=301]

Can someone help me with this?

1

There are 1 best solutions below

0
On BEST ANSWER

I suggest not using .php in pretty URL, make it extension-less. Try these rules in v2/.htaccess:

RewriteEngine On
RewriteBase /v2/

RewriteCond %{THE_REQUEST} /message\.php\?ID2=([^&\s]+) [NC]
RewriteRule ^ message-%1? [NE,R=302,L]

RewriteRule ^message-(.+)/?$ message.php?ID2=$1 [L,QSA,NC]