Home Ask Login Register

Developers Planet

Your answer is one click away!

Webbly Brown February 2016

Rewrite directory to another to stop 404 with htaccess

A decision was recently made to rename a directory on our website. I now have a number of old url's indexed by google that return 404 errors.

I would like to try and create a rewrite with .htaccess to resolve this problem. The directory was renamed from job to jobs

So for example I would like: https://myurl.com/job/Sales-Manager-Jobs-In-Havant

To look like: https://myurl.com/jobs/Sales-Manager-Jobs-In-Havant

I already have some rewriting in place which already creates these SEO friendly urls from something like single-joblisting.php?id=1

This sits in the jobs directory and looks like this:

Options -MultiViews
RewriteEngine on
RewriteBase /jobs/

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\w-]+)/?$ single-joblisting.php?id=$1 [L,QSA]

I had to ask for help to get the above rewrite working. So could anyone also help with this issue?


starkeen February 2016

You can use the following Redirect:

RedirectMatch 301 ^/job/(.+)$ /jobs/$1

This will permanently redirect

  • /job/foobar


  • /jobs/foobar

Post Status

Asked in February 2016
Viewed 1,817 times
Voted 10
Answered 1 times


Leave an answer

Quote of the day: live life