skip to Main Content

I read a lot on 301 redirects of full domains, but couldn’t get how to exactly change an existing path to a new one.

Here is an example:

site.com/cars to site.com/motobikes

And:

site.com/cars/tires to sote.com/motobikes/(variable ex. Berlin, Paris)/tires

How can I accomplish this task?

2

Answers


  1. You can make a redirect like this way in PHP

    header("HTTP/1.1 301 Moved Permanently"); 
    header("Location: http://www.example.com/$var"); 
        exit();
    

    Or you can use a .htaccess file Redirect 301 /cars http://example.com/motobikes

    Login or Signup to reply.
  2. Try this:

    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^example.com
    RewriteRule ^cars http://example.com/motorbikes [R=301,L]
    

    And:

    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^example.com
    RewriteRule ^cars/tires http://example.com/motobikes/berlin/tires [R=301,L]
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search