1

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?

4
  • Looks like you changed the wrong side. Try replacing the - in the original rule with a / Commented May 7, 2015 at 22:11
  • @JonStirling do you mean RewriteRule ^(.*)/wallpaper/(.*)$ $1/wallpaper-$2 [R,L] Commented May 7, 2015 at 22:13
  • How did you take that from my comment? To be honest, I keep reading your question and I'm not actually sure what you're after. Are you after a rule replacement to replace your current rule to work with the new structure, or are you after just the rule to redirect the old URLs to the new ones? Or both / neither? Commented May 7, 2015 at 22:18
  • @JonStirling i wanted to convert asdf.com/prefix-any-string-{id}.html to asdf.com/prefix/any-string-{id}.html Commented May 7, 2015 at 22:28

1 Answer 1

2

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]
Sign up to request clarification or add additional context in comments.

3 Comments

thanks for your reply. however this worked for me: RewriteRule ^(wallpaper)-([^.]+\.html)$ http://domain.com/$1/$2 [R=302,L,NC] RewriteRule ^wallpaper/([^.]+)\.html$ wallpaper.php?permalink=$1 [L,NC,QSA]
Never use a 302, you'll zap all your link juice. Use a 301 instead.
302 is for testing only the change otherwise browser will cache unwanted URLs. Once tested it can be changed to 301

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.