.htaccess 我做错了什么?
我正在使用Opencart,启用了SEO友好的url 这使得.htaccess文件看起来像这样.htaccess 我做错了什么?,.htaccess,.htaccess,我正在使用Opencart,启用了SEO友好的url 这使得.htaccess文件看起来像这样 RewriteRule ^sitemap.xml$ index.php?route=feed/google_sitemap [L] RewriteRule ^googlebase.xml$ index.php?route=feed/google_base [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-
RewriteRule ^sitemap.xml$ index.php?route=feed/google_sitemap [L]
RewriteRule ^googlebase.xml$ index.php?route=feed/google_base [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css)
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]
但我需要添加一个不会被重写的文件夹异常,特别是/emailer
在网络上查找答案时,我做了以下操作:
RewriteCond %{REQUEST_URI} !^/(emailer|js|css)/ [NC]
RewriteRule ^ - [L]
RewriteRule ^sitemap.xml$ index.php?route=feed/google_sitemap [L]
RewriteRule ^googlebase.xml$ index.php?route=feed/google_base [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css)
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]
这使得/emailer/可以工作,但另一种重写则不行。有人知道我做错了什么吗 只需将其插入主重写规则之前即可
RewriteBase /
RewriteRule ^sitemap.xml$ index.php?route=feed/google_sitemap [L]
RewriteRule ^googlebase.xml$ index.php?route=feed/google_base [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^\/(emailer|js|css) [NC]
RewriteCond %{REQUEST_URI} !\.(ico|gif|jpg|jpeg|png|js|css)$ [NC]
RewriteRule ^([^?]*) index.php?_route_=$1&request_uri=%{REQUEST_URI} [L,QSA]
注意:它没有经过测试,但这会让您知道如何进行测试
以后编辑:
我已经测试了我的代码,但它不起作用。我已经编辑了它,现在它可以工作了,如下所示:
RewriteCond%{REQUEST\u FILENAME}-f
=>如果请求不是真实的文件名RewriteCond%{REQUEST\u FILENAME}-d
=>如果请求不是真实目录RewriteCond%{REQUEST\u URI}^\/(emailer | js | css)[NC]
=>如果根目录中没有以emailer/js/css开头的目录/文件RewriteCond%{REQUEST\u URI}!\。(ico | gif | jpg | jpeg | png | js | css)$[NC]
=>如果请求未以以下ico/gif/jpg/jpeg/png/js/css的扩展名结束- 要测试重写规则中是否需要正斜杠,请像我在修改的示例中那样附加一个查询变量,并在index.php文件中打印它(在php open标记后的第一行),如下所示: 打印($\u GET['request\u uri']); 退出
- 总是用反斜杠来避开正斜杠,就像这样\/