0

I would like to change the root directory of my website from the 'e' folder (http://www.domainname.com/e) to 'wp' folder(http://www.domainname.com/wp). How do I go about this using the .htaccess file?

1
  • there's something related to this on your htaccess already?
    – Tomás Cot
    Commented Sep 14, 2014 at 23:00

1 Answer 1

1

Why do you want to use .htaccess to do this? Why not just move to the new URL?

Alternatives include adding something similar to one of the following to your .htaccess file (note the 301 "permanently moved" code being sent back to the browser in both cases):

RedirectMatch 301 /e /wp

or

<IfModule mod_rewrite.c>
   RewriteEngine On
   RewriteCond %{HTTP_HOST} ^domainname\.com/e [NC]
   RewriteRule ^(.*)$ http://www.domainname.com/wp/$1 [R=301,L]
</IfModule>

Or use your wp-config.php file by defining these two constants at the top:

define('WP_SITEURL', 'http://www.domainname.com/wp');
define('WP_HOME', 'http://www.domainname.com/wp');

Or better (avoid redirects and avoid WordPress doing on-the-fly conversions), use the wp-cli tool to safely do a global search and replace to change your old URL to your new URL throughout your WordPress site:

su -s /bin/bash www-data -c "wp search-replace 'http://www.domainname.com/e' 'http://www.domainname.com/wp' --recurse-objects"

The above example forces the wp-cli tool to run in the security context of the www-data user account, so adjust to suit. If you're running the site at a hosting service that is WordPress savvy,they'll have instructions about how to use wp-cli on their servers.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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