0

I would like to rewrite http://example.com/test/index.php?id=123 to http://example.com/test/item/123/ and http://example.com/test/index.php?id=123 redirect to the human friendly url.
I don't know what is wrong in my htaccess :

Options +FollowSymLinks -MultiViews

RewriteEngine On    
RewriteBase /test/

RewriteCond %{QUERY_STRING} ^id=([a-z0-9]+)$ [NC]
RewriteRule ^/item/%1/? [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^item/([a-z0-9]+)/$ index.php?id=$1 [L]

1 Answer 1

1

You can use the following RewriteRule in your /test/.htaccess file

Options +FollowSymLinks -MultiViews
RewriteEngine on

#redirect old url to the new one
RewriteCond %{THE_REQUEST} /test/index\.php\?id=([^\s]+) [NC]
RewriteRule ^ /test/item/%1? [L,R=301]
#internally map new url to the old one
RewriteRule ^item/(.+)/?$ /test/index.php?id=$1 [L,NC]
Sign up to request clarification or add additional context in comments.

1 Comment

Nice and precious, thank you — it's work with my regexp [a-z0-9]+

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.