2012-12-12 170 views
0

编辑:我必须添加的东西。首先,我想改变URL显示,因为SEO。如果我使用WWW到达我的网站没有问题,第二个链接出现,一切都OK。RewriteCond查询字符串.htaccess

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

我想改变

​​

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] 

回答

1

也许这是你在找什么:

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

如果你有视觉上改变地址栏,离开重写规则的地方,因为我描述以上,并在任何输出之前将其写入index.php

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

谢谢,你打我去修复这个错字;) – BenM

+0

当我添加内部服务器时发生错误。 :/ – codeGenius

+0

@BenM:任何时间...大声笑 – cHao

0

首字记:我不是Apache大师,所以不要盲目依赖我的答案。

如果需要

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指定的页面可能需要我会首先重定向到www.改变与HTTP_HOST

+0

只要重定向到“我”,我实际上更喜欢将所有内容重定向到非“.www”域。 “www.'版本只是停留在周围,因为一群人受过训练,”网站地址以'www'开头“。但我想引导人们远离那种无意义的东西。 (不过,无论如何,这是一笔不小的交易;无论您是否重定向www,或者不重定向到哪个域,对于实际问题都无关紧要。) – cHao