2013-05-03 214 views
0

我正在使用Opencart的SEO Friendly URL已打开。RewriteCond - 我做错了什么?

这就是所做的.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] 

但我需要在一个文件夹不同的是没有得到改写,特别是/电子邮件使用者

寻找各地的网络,在回答加我做了以下事情:

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] 

这使得/电子邮件/工作,但其他重写不。有谁知道我在这里做错了吗?

回答

0

你只要在主要的RewriteRule之前插入它。

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] 

注:它没有测试,但是这应该给你的想法如何做到这一点。

后来编辑:

我已经测试我的代码,并没有奏效。我已经编辑它,它现在的工作,是这样的:

  1. RewriteCond %{REQUEST_FILENAME} !-f =>如果请求是不是一个真正的文件名
  2. RewriteCond %{REQUEST_FILENAME} !-d =>如果请求是不是一个真正的目录
  3. RewriteCond %{REQUEST_URI} !^\/(emailer|js|css) [NC] =>如果如果请求没有以以下ico/gif/jpg/jpeg/png/js/js文件的扩展名结尾,那么根目录中没有以emailer/js/css开头的目录/文件
  4. RewriteCond %{REQUEST_URI} !\.(ico|gif|jpg|jpeg|png|js|css)$ [NC] = css

注:

  • 测试如果你需要在你的重写规则斜线与否,追加查询变量就像我在我的修改例子一样的,而PHP后打印(在第一行打开标签)在你的index.php文件中是这样的:

    print_r($ _ GET ['request_uri']); 退出;

完成测试后,从htacces和index.php中删除request_uri。

  • 总是用反斜杠逃逸的斜杠,这样\/
+0

这没有遗憾的工作。它仍然是重写/电子邮件。我试着把它放在ico/gif之前和之后等,然后我试着取消它到RewriteCond%{REQUEST_URI}!^/emailer/[NC]。仍然没有运气。 – jimbeeer 2013-05-03 09:03:35

+0

我在尝试很多不同的组合。它会崩溃或重写网站。这是我到目前为止: 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}! - RewriteCond%{REQUEST_URI}!\。(ico | gif | jpg | jpeg | png | js | css)$ [N] RewriteCond%{REQUEST_URI}!^/emailer /?$ RewriteRule ^([^?] *)index.php?_route _ = $ 1 [L,QSA] – jimbeeer 2013-05-03 09:40:15