Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.htaccess 我做错了什么?_.htaccess - Fatal编程技术网

.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} !-

我正在使用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} !-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']); 退出

    完成测试后,从htacces和index.php中删除请求uri

    • 总是用反斜杠来避开正斜杠,就像这样\/

    不幸的是,这不起作用。它仍在重写/发送电子邮件。我试着把它放在ico/gif之前和之后,等等。然后我试着取消它以重写cond%{REQUEST_URI}^/emailer/[NC]。还是不走运。我尝试了很多不同的组合。它要么崩溃,要么重写站点。到目前为止,我已经做到了: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}-已重写cond%{REQUEST\u URI}!\。(ico | gif | jpg | jpeg | png | js | css)$[NC]RewriteCond%{REQUEST_URI}^/emailer/?$RewriteRule^([^?]*)index.php?\u route\uu=$1[L,QSA]