RewriteCond查询字符串.htaccess

时间:2012-12-12 23:28:21

标签: mod-rewrite

编辑:我必须添加一些东西。首先,我想改变URL显示因为SEO。如果我使用www到达我的网站没有问题,第二个链接出现,一切正常。

但是,如果我从链接中删除“www”,它会更改为第一个网址,我不希望这样。

我想改变

http://www.mysite.com/index.php?route=epson-claria-uyumlu-yazici-kartus-dolum-murekkebi-500g.html

http://www.mysite.com/epson-claria-uyumlu-yazici-kartus-dolum-murekkebi-500g.html

我该怎么做?

我试过

RewriteCond %{QUERY_STRING} ^_route_=(.*)$
RewriteRule ^index\.php$ /%1 [R=301,L]

但它不起作用。

我的.htaccess是

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} !.*\.(ico|gif|jpg|jpeg|png|js|css)
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]

RewriteCond %{QUERY_STRING} ^route=common/home$
RewriteRule ^index\.php$ http://www.mysite.com? [R=301,L]

RewriteCond %{HTTP_HOST} !^www\.mysite\.com$
RewriteRule (.*) http://www.mysite.com/$1 [R=301,L] 

2 个答案:

答案 0 :(得分:1)

也许这就是你要找的东西:

RewriteRule ^(.*)$ index.php?route=$1 [L]

如果您必须在视觉上更改地址栏,请按照上述说明将RewriteRule保留在原位,并在输出之前将其放在index.php中:

if(isset($_REQUEST['route']))
{
    header('Location: '.urlencode($_REQUEST['route']));
}

答案 1 :(得分:0)

初步说明:我不是Apache大师,所以不要盲目依赖我的答案。

如果需要,我会首先重定向到www.

RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{SERVER_NAME}/$1 [R=301,L]

然后转到_route_查询变量

指示的页面
# if it is the index page...
RewriteCond %{REQUEST_URI} ^/(index\..+)?$ [NC]
# and if the query string starts with _route_=
RewriteCond %{QUERY_STRING} ^_route_=(.*)$
# redirect
RewriteRule ^(.*)$ http://%{SERVER_NAME}/%1? [R=301,L]

最后一行中的服务器变量SERVER_NAME可能需要使用HTTP_HOST进行更改。

相关问题