简体   繁体   中英

Difficulties to correctly apply a htaccess RewriteRule

I've got this code in my .htaccess file:

RewriteEngine on
RewriteBase /testsite/
RewriteRule ^admin/(.*) administrator/$1
RewriteCond %{THE_REQUEST} ^GET\ /^administrator/
RewriteRule ^administrator/(.*) admin/$1 [L,R=301] 

Working

My actual URL is: http://localhost/mysite/administrator/

When I type http://localhost/mysite/admin it's retrieving the correct page.


Failing

When I try to request the page using http://localhost/mysite/administrator/ , it should apply a rewrite to http://localhost/mysite/admin , but no avail.

Seems that redirecting is working, but rewriting isn't.
Any help on this?

Your error is that you have a stray ^ in your RewriteCond matching THE_REQUEST before "administrator":

RewriteCond %{THE_REQUEST} ^GET\ /^administrator/

To:

RewriteCond %{THE_REQUEST} ^GET\ /administrator/
RewriteEngine on

RewriteBase /mysite/

RewriteRule ^administrator /admin [L,R=301]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM