htaccess url rewrite help

£可爱£侵袭症+ 提交于 2019-12-12 03:22:42

问题


I have the following rewrite URL:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Rewrite all other URLs 
RewriteRule ^(.*)$ index.php?page=$1 [PT,L]

Now I want to add an exception, that if the URL is something like mysite.com/abc it should ignore it and all things inside it also. mysite.com/abc/dfgs also should be excluded from this rewriting.

How can I accomplish this?


回答1:


If /abc is an existing directory, you can put another .htaccess file in there with

RewriteEngine Off  

If it's really just one string you want to not rewrite (whether it exists or not)

RewriteCond %{REQUEST_URI} !^/abc  

will not rewrite if the requested path starts with "/abc"

To test rewrite rules without messing up the site for regular browsers (not that you should be editing in a live environment of course, this is purely hypothetical :-) ), I've found the following very helpful:

RewriteCond %{REMOTE_ADDR} 12.34.56.78 # <-- where that's your IP address  



回答2:


This should avoid rewriting if the URI contains abc. This may or may not be exactly what you want. If it isn't edit your question.

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

#Rewrite ONLY if the REQUEST does NOT contain abc
RewriteCond %{REQUEST_URI} !abc

# Rewrite all other URLs 
RewriteRule ^(.*)$ index.php?page=$1 [PT,L]


来源:https://stackoverflow.com/questions/1055281/htaccess-url-rewrite-help

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!