【发布时间】:2018-03-16 09:16:17
【问题描述】:
我需要一个域来管理语言 (en/it/pt/es) 并删除 www。并强制 https
重写引擎开启 # -> www.example.com 到 example.com RewriteCond %{HTTP_HOST} www.example.com 重写规则 (.*) http://example.com/$1 [L,R=301] # -> http -> https RewriteCond %{SERVER_PORT} 80 RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]我不知道如何制定这个重写规则: index.php?lg=es -> /es/ 而不是 /es 或 /es.php 甚至拒绝 index.php?lg=es
重写规则 ^([a-zA-Z0-9]+)/?$ index.php?lg=$1
??
搜索引擎优化对我的网站不利,引擎只知道英语,其他语言在结果的第 4 页。
这是因为我有两种显示网址的原因吗??
example.com/it/ 和 example.com/it 不应返回同一页面
感谢您的帮助。
编辑(我认为一切都是正确的??):10 月 7 日,感谢所有回答:
重写引擎开启 RewriteCond %{HTTP_HOST} ^www.example.com$ [OR] RewriteCond %{SERVER_PORT} 80 [或] RewriteCond %{HTTPS} 关闭 重写规则 ^(.*)$ https://example.com/$1 [R=301,L] 重写规则 ^/?([a-z]{2})$ /$1/ [R=301,NC,L] 重写规则 ^/?([a-z]{2})/$ /index.php?lg=$1 [NC] 重写条件 %{ENV:REDIRECT_STATUS} ^$ RewriteCond %{REQUEST_URI} ^/?index.php$ RewriteCond %{QUERY_STRING} ^lg=([^&]+)(&.*)?$ 重写规则 ^/?index.php$ - [F] 错误文档 404 /404.php只是一个问题:测试 https 关闭是否真的有用(连接速度慢?)?谢谢
2018 年 2 月 8 日编辑
使用几个月后,出现很多 404 错误。 Htaccess 需要更加简化。
我只需要:
1) www -> non-www
2) http -> https
3) index.php -> example.com
4) redirect index.php?lg=it and index.php?lg=es and index.php?lg=pt
to example.com/it or to example.com/es or to example.com/pt
如果它不是这种语言中的一种 -> 转到主页 example.com 或 404 ??但是谷歌站长会增加404错误...
我需要一个非常简化的 htaccess 版本,其中包含 3 种语言和 Rewrite Base 吗?或不 ?
这是我的 htaccess :
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.example.com$ [OR]
RewriteCond %{SERVER_PORT} 80 [OR]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]
RewriteRule ^/?([a-z]{2})$ /$1/ [R=301,NC,L]
RewriteRule ^/?([a-z]{2})/$ /index.php?lg=$1 [NC]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{REQUEST_URI} ^/?index.php$
RewriteCond %{QUERY_STRING} ^lg=([^&]+)(&.*)?$
RewriteRule ^/?index.php$ - [F]
ErrorDocument 404 /404.php
一切都在 index.php 中管理,创建 3 个页面会更好吗?
index.php -> 重定向到 example.com
es.php -> 重定向到 example.com/es
it.php -> 重定向到 example.com/it 删除 .php
有人能做到吗?谢谢
【问题讨论】:
-
我们无法告诉您您的 SEO 很糟糕。有很多可能的原因,因此这里讨论它的地方是错误的。
-
如果我们有一个像 example.com/it/some-page 这样的 URL 会发生什么......并且 example.com/it/ 和 example.com/it 应该提供相同的页面恕我直言,如果不请解释原因
-
感谢您的回复,我认为 example.com/it/ 和 example.com/it 可能被视为重复内容?在许多网站上 /it 重定向到 /it/
-
你只在硬代码域中使用了我的答案...
-
是的,我使用您的代码,但我需要更多积分(声誉)才能投票,所以我不能抱歉..
标签: php apache .htaccess mod-rewrite