防止访问 seo 不友好的 url 并重定向到 seo 友好的(规范的)url
Preventing access to seo-unfriendly URLs and redirect to seo-friendly (canonical) URLs
我看到很多类似的问题,但 none 到目前为止帮助了我:
我的脚本逻辑在 /song/song.php?url=lang/params 下(seo 不友好 URL)。我使用此重写来获得友好的 URL 并从 seo 不友好的内容加载内容,使用参数来区分语言:
RewriteRule ^songs-and-chords/(.*?)(/*)?$ /song/song.php?url=en/ [NC,L]
RewriteRule ^canzoni-e-accordi/(.*?)(/*)?$ /song/song.php?url=it/ [NC,L]
现在我想阻止访问 /song/song.php,强制重定向到 seo 友好的,所以像这样,使用 %{THE_REQUEST} 到进行外部重定向:
RewriteCond %{THE_REQUEST} .*?song/song\.php\?url=it/(\S*) [NC]
RewriteRule /canzoni-e-accordi/ [R,L]
RewriteCond %{THE_REQUEST} .*?song/song\.php\?url=en/(\S*) [NC]
RewriteRule /songs-and-chords/ [R,L]
RewriteCond %{THE_REQUEST} ^.*?song/song\.php.*$ [NC]
RewriteRule /songs-and-chords/ [R,L]
但是没有执行此规则...我做错了什么?我怎样才能很好地调试它?
(我已经在 song.php 脚本中使用了 rel="canonical",但我仍然希望该脚本根本无法访问)。
您做错的是,缺少 RewriteRule
语句的模式。此外,重写的 URL 将使用 %1
引用而不是 </code>.</p>
<pre><code>RewriteCond %{THE_REQUEST} ^GET\ /song/song\.php\?url=it/(\S+) [NC]
RewriteRule ^ /canzoni-e-accordi/%1? [R=301,L]
RewriteCond %{THE_REQUEST} ^GET\ /song/song\.php\?url=en/(\S+) [NC]
RewriteRule ^ /songs-and-chords/%1? [R=301,L]
RewriteCond %{THE_REQUEST} ^GET\ /song/song\.php\s [NC]
RewriteRule ^ /songs-and-chords/ [R=301,L]
我看到很多类似的问题,但 none 到目前为止帮助了我:
我的脚本逻辑在 /song/song.php?url=lang/params 下(seo 不友好 URL)。我使用此重写来获得友好的 URL 并从 seo 不友好的内容加载内容,使用参数来区分语言:
RewriteRule ^songs-and-chords/(.*?)(/*)?$ /song/song.php?url=en/ [NC,L]
RewriteRule ^canzoni-e-accordi/(.*?)(/*)?$ /song/song.php?url=it/ [NC,L]
现在我想阻止访问 /song/song.php,强制重定向到 seo 友好的,所以像这样,使用 %{THE_REQUEST} 到进行外部重定向:
RewriteCond %{THE_REQUEST} .*?song/song\.php\?url=it/(\S*) [NC]
RewriteRule /canzoni-e-accordi/ [R,L]
RewriteCond %{THE_REQUEST} .*?song/song\.php\?url=en/(\S*) [NC]
RewriteRule /songs-and-chords/ [R,L]
RewriteCond %{THE_REQUEST} ^.*?song/song\.php.*$ [NC]
RewriteRule /songs-and-chords/ [R,L]
但是没有执行此规则...我做错了什么?我怎样才能很好地调试它?
(我已经在 song.php 脚本中使用了 rel="canonical",但我仍然希望该脚本根本无法访问)。
您做错的是,缺少 RewriteRule
语句的模式。此外,重写的 URL 将使用 %1
引用而不是 </code>.</p>
<pre><code>RewriteCond %{THE_REQUEST} ^GET\ /song/song\.php\?url=it/(\S+) [NC]
RewriteRule ^ /canzoni-e-accordi/%1? [R=301,L]
RewriteCond %{THE_REQUEST} ^GET\ /song/song\.php\?url=en/(\S+) [NC]
RewriteRule ^ /songs-and-chords/%1? [R=301,L]
RewriteCond %{THE_REQUEST} ^GET\ /song/song\.php\s [NC]
RewriteRule ^ /songs-and-chords/ [R=301,L]