简体   繁体   中英

URL rewrite conflicting rules

I'm having problems getting my URL rewrite to work, I currently have these 3 rules

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?/$1 [QSA,L]

and I want to add a rule where if the user hits http://example.com/metrics/ , it sends them to index.php?/sign-in

I've tried doing RewriteRule /metrics/(.*) /index.php?/sign-in [PT] , but it seems to be conflicting with the .* rule and not sending the user to /index.php?/sign-in at all.

If you have logically conflicting rules, put the more specific before the more general.

For your purpose, something like this should work:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^metrics/?(.*)$ /index.php?/sign-in [QSA,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [QSA,L]

As an aside, you may want to consider revising your approach.

What if the user is already signed in? Perhaps, your /metrics page should behave (.htaccess wise) the same as your other pages, and have its code do the equivalent of if( !SignedIn() ) Redirect( "/sign-in" ) in your language of choice.

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