我有一个.htaccess文件,但我不确定它是否会伤害我,而不是帮助我。我应该如何做得更好,让搜索引擎不会因重复内容而惩罚我?
我不希望他们将login.php或/ login,只是/ login /排名。而且,如果有人访问login.php或/ login,我希望他们被强制使用/ login /。我该怎么做并正确优化?
RewriteEngine On
RewriteBase /
RewriteRule ^login/$ login.php [NC,L]
RewriteRule ^register/$ register.php [NC,L]
RewriteRule ^recover/$ recover.php [NC,L]
RewriteRule ^recover/([a-z0-9]+)/$ recover.php?code=$1 [NC,L]
RewriteRule ^game/([a-z0-9-]+)/$ game.php?game=$1 [NC,L]
答案 0 :(得分:1)
您可以使用一些新的重定向规则重定向到漂亮的网址:
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} /(register|login|recover)(?:\.php)?[\s?] [NC]
RewriteRule ^ /%1/ [R=302,L,NE]
RewriteCond %{THE_REQUEST} \s/+(game|recover)\.php\?code=([^\s&]+) [NC]
RewriteRule ^ /%1/%2/? [R=302,L,NE]
RewriteRule ^(register|login|recover)/$ $1.php [NC,L]
RewriteRule ^(game|recover)/([a-z0-9]+)/$ $1.php?code=$2 [NC,L,QSA]