I have one page that I need to change the URL for.

Currently, the page resides at example.com/departments/human-resources/

(human-resources is a sub-page of /departments/ )

My client wants to maintain the legacy url for the hr department which is:

http://example.com/hr/

How can I rewrite any request for ^/hr/?$ to ^/departments/human-resources/$ but keep the URL the same?

That is, nobody will ever see /departments/human-resources/.

My current .htaccess looks like this:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

I've tried adding a rewrite rule that writes /hr/ to /dept/h-r/ before the index.php line, but this gives me a 404.

up vote 1 down vote accepted

Redirection allows you to modify post slugs and keeps a history of them, pointing all requests for the history of a page to the same destination. It's useful for all sorts of other things too, but it will definitely solve this problem.

One time rewrite rules are actually built into the post type edit/new UI.

You can either use the Permalink edit line below the title or open the Screen Options tab and set the meta box to visible (check the checkbox).

enter image description here

  • Unfortunately, I won't be able to removed the /departments/ before the human resources part. by using this method – jessh Dec 5 '12 at 14:32
  • @jessh "How can I rewrite any request for ^/hr/?$ to ^/departments/human-resources/$" clearly states the opposite. – kaiser Dec 5 '12 at 16:00
  • no... The request URI would be http://example.com/hr/. This should redirect to http://example.com/departments/human-resources/. Your solution will only let me change whatever comes after /departments/ – jessh Dec 6 '12 at 15:00

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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