Angela Taylor
Angela Taylor

Reputation: 151

changing url structure with htaccess

i have a url

http://domain.com/wallpaper-name-of-wallpaper-id.html

where wallpaper- is prefix of the url and name-of-wallpaper is title of the wallpaper while id is the actual id of the wallpaper. my current .hataccess file looks like.

RewriteRule ^wallpaper-([^/]*)\.html$ wallpaper.php?permalink=$1 [L]

but i want to change it to

http://domain.com/wallpaper/name-of-wallpaper-id.html

so user who will enter the old url will automatically sent to the new url with htaccess.

i have tried. RewriteRule ^wallpaper-([^/]*)\.html$ wallpaper/wallpaper.php?permalink=$1 [R,L]

but don't seems to work for me. any idea or help?

Upvotes: 1

Views: 593

Answers (1)

anubhava
anubhava

Reputation: 785038

Add a new redirect rule before existing rule:

Options -MultiViews
RewriteEngine On

RewriteRule ^(wallpaper)-([^.]+\.html)$ /$1/$2 [R=302,L,NC]

RewriteRule ^wallpaper/([^.]+)\.html$ wallpaper.php?permalink=$1 [L,NC,QSA]

Upvotes: 2

Related Questions