Write htaccess rewrite rule which should be point to a directory which is not existing in app directory structure

Write htaccess rewrite rule which should be point to a directory which is not existing in app directory structure - .htaccess files are extremely useful in many cases for users who either do not have root permissions or for users who simply aren't comfortable in making changes in their web server's configuration file. Trying to debug .htaccess not working isn't always the easiest thing to do, however, hopefully by checking the discuss below mentioned about web-hosting, htaccess, redirects, wordpress, .htaccess common problems as well as the troubleshooting tips, you'll have a better grasp on what you may have to modify to get your .htaccess file running smoothly.Problem :


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?


Solution :

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!


Additionally, if you would like to do some further testing, give the htaccess tester tool a try. It allows you to specify a certain URL as well as the rules you would like to include and then shows which rules were tested, which ones met the criteria, and which ones were executed.

Comments

Popular posts from this blog

Rewrite in Mediawiki, remove index.php, .htaccess

.htaccess rewrite wildcard folder paths from host

Using .htaccess to set a cookie and 301 redirect