Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a website for classifieds ads. Before I used to modify the URLs to make them more appropriate, but the old URLs are still showing up in Google index and in browser history/bookmarks.

Is there any way to by pass or redirect the old URLs to the new ones? I tried using .htaccess rules but cant get the the result I want.

For example:

  1. Before modification
  2. After modification

As it happens at the moment, both of the URLs work, which is bad for Search Engine Optimization (SEO). I need the first URL to redirect to the second URL.

This is exactly what is in my .htaccess file:

AddHandler application/x-httpd-php5s .php
ErrorDocument 404 /content/404.php
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteRule ^vehicles-cars/?(.*),,,,,,,,,,,,,,,  
share|improve this question

What webserver are you running? Edit that in your question please.

Assuming it's Apache and you have mod_rewrite on, append the following line in your .htaccess file found at the root directory of your host.

RewriteRule ^vehicles-cars/?(.*)$1

It should do the trick.

share|improve this answer
thanks Panagiotis M for your quick response this trick i already used in my .htaccess file but not working this is what exactally is in my .htaccess file actually the problem – david Aug 30 '12 at 4:29
thanks Panagiotis M for your quick response this trick i already used in my .htaccess file but not working i am adding details in main post thanks again for prompt reply – david Aug 30 '12 at 4:37
The snippet I gave as an aswer should do be working, any match to vehicles-cars is redirected to the correct/new url type. Now regarding the 'middle' parameters of the url as you stated in your edited post, I am guessing that the script you are using just examines the accessed url and sends out content as a match from the last integer number. – Panagiotis M. Aug 30 '12 at 13:14

You need to do a 301 redirect from the old URL. Given that both of those URLs currently work, I wouldn't touch your rewrite rules, as I think that will be more complicated than it needs to be, because you will need to know which one is the current URL and which one is the old URL at rewrite level, which it looks like your app is not designed for.

What I would do instead, is when the PHP starts executing, the first thing it needs to do is check the current URL of the request (content-location). Compare what's in that string to what's in your database for the page.

If the two URLs match, then load the page normally. Otherwise, do a 301 Header Redirect to the new URL.

share|improve this answer

see this: 301 and 302 redirects using mod rewrite tutorial

share|improve this answer
Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference. – Mark Henderson Aug 29 '12 at 21:51
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. – Michael Hampton Aug 29 '12 at 23:20

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.