Andy Gosling
Andy Gosling

Reputation: 13

.htaccess 301 redirect workaround

A client is placing a recruitment advert in the press featuring a custom url:

e.g. www.clientsname.com/newjob

...this page does not exist on the site but when people visit it they want it to redirect to their recruitment page:

e.g. www.clientsname.com/recruitment

This is how their .htaccess file currently looks:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?action=PublicDisplayPage&url=$1 [L,QSA]

...I don't pretend to understand what the above does! However, I tried the following for the redirect:

Redirect 301 /newjob www.clientsname.com/recruitment

but this resulted in this url:

http://www.clientsname.com/recruitment?action=PublicDisplayPage&url=newjob

Can anyone tell me what I need to do to get it to redirect to just www.clientsname.com/recruitment - i.e. without the ?action=PublicDisplayPage&url=newjob

Many thanks!

Upvotes: 0

Views: 167

Answers (1)

Jon Lin
Jon Lin

Reputation: 143906

The Redirect directive is a mod_alias directive, and the routing to /index.php is via mod_rewrite. Both modules processed the same URI, so they both mangle the URI. In this case, you need to stick with just mod_rewrite:

RewriteEngine On

RewriteRule ^/?newjob(.*)$ /recruitment$1 [L,R=301]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?action=PublicDisplayPage&url=$1 [L,QSA]

It's important to have the redirect before the routing rule, otherwise the redirect will never happen.

Upvotes: 1

Related Questions