0

编辑:我必须添加一些东西。首先,由于 SEO,我想更改 url 显示。如果我使用 www 访问我的网站,没有问题,第二个链接出现,一切正常。

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

我想改变

http://www.mysite.com/index.php? 路线= 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] 
4

2 回答 2

1

Maybe this is what you're looking for:

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

If you have to visually change the address bar, leave the RewriteRule in place as I described above, and put this in your index.php before any output:

if(isset($_REQUEST['route']))
{
    header('Location: '.urlencode($_REQUEST['route']));
}
于 2012-12-12T23:30:25.800 回答
1

初始说明:我不是 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.

于 2012-12-13T01:24:39.613 回答