I need to write a rewrite rule so that the url should be point to a directory which is not existing in the application directory. In WordPress all admin process/code in wp-admin, so someone try to login, the url in clients browser will rewrite to http://example.com/wp-admin/*php. I need to avoid that, I wish the browser should show the directory ec-admin instead of wp-admin. That is http://example.com/ec-admin/*php This should achieve only by editing htaccess instead of editing entire code.

Here is my .htaccess file

RewriteEngine On 
RewriteBase / 
RewriteRule ^index.php$ - [L] 
RewriteRule ^wp-admin/(.*) /ec-admin/$1 [R=301,NC,L]

But now its showing file not found error, is there anyway to fix it?

  • Any web server will throw up a 404 for something that does not exist. I am not sure what you are trying to achieve. Can you explain the motivation and thought behind this so that we can better understand??
    – closetnoc
    Commented Feb 5, 2015 at 16:59
  • For example, wordpress site core folder is wp-admin, so when someone need to login, the site will pointed to wp-admin, the browser will show that wp-admin in url. I need to avoid that condition, instead of wp-admin i need to show another directory. Commented Feb 5, 2015 at 17:09
  • Okay. I will let a WP person answer. They might understand your motivation better based upon experience. I have to run away on business for a few hours.
    – closetnoc
    Commented Feb 5, 2015 at 17:12
  • Yes bybe like as below http://example.com/blog/admin.php?page=orders to http://example.com/admin/admin.php?page=orders Commented Feb 5, 2015 at 17:25

1 Answer 1


Sadly with most content management systems its not always as easy to make a simple rewrite in the .htaccess file since the paths are driven from settings in the php and that of your database, this can cause looping effect or a 404 error.

Generally rewriting urls from one from to another while keeping the query string intact will look something like:

RewriteRule ^admin/(.*?) ec-admin/$1 [QSA]

Notice the [QSA] this will keep the query string in tact while renaming admin to ec-admin.

If you find that your website is having unnecessary additional redirect hops, a loop or a 404 error then its likely because WordPress is driving the permalinks as mentioned, thankfully WordPress is extremely popular and there's dozens of plugins that will allow you to edit permalinks in the dashboard or alternatively rename the admin folder for security or other reasons!

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.