Needs some help with an apache mod-rewrite issue

浪尽此生 提交于 2019-12-20 04:36:47

问题


I've modified my .htaccess file to have the following statement

RewriteCond $1 !^index.php$
RewriteRule ^/?([^/]+)$ index.php?c=home&m=details&seo=$1 [L,NS]

This allows me to use product URL's like this: http://domain.com/product_name

However, when trying to access a file at the same level as index.php, it always calls the RewriteRule above and errors out.

I need to be able to access files like below, but each URL currently attempts to load index.php. http://domain.com/about.htm
http://domain.com/terms.htm
http://domain.com/robots.txt
etc

Any suggestions on how I can modify my htaccess file to get this to work correctly?


回答1:


If you want files to trump products you could toss in another condition:

RewriteCond $1 !^index.php$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/?([^/]+)$ index.php?c=home&m=details&seo=$1 [L,NS]

...meaning that only if the requested URI doesn't map to a file should it be treated as a product.

Having files trump products like this isn't terrible unless you plan on having products with names like "something.html" and "dynamic.php" or "lenna.jpg".



来源:https://stackoverflow.com/questions/2549408/needs-some-help-with-an-apache-mod-rewrite-issue

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