如何使用 htaccess 重定向一堆文件
how to redirect a bunch of files with htaccess
我有一个网站有很多 url 这样的
www.example.com/this_has_some_meaning.php
现在我了解到,出于 SEO 的原因,最好使用
www.example.com/this-has-some-meaning.php
我可以使用 htaccess,使用某种正则表达式将所有 url 从旧的重定向到新的吗?
您可以在 .htaccess 中使用这两条规则:
RewriteEngine On
# when there is only one underscore then redirect
RewriteRule ^([^_]*)_+([^_]*)$ /- [L,R=301,NE]
# otherwise replace each _ by - recursively
RewriteRule ^([^_]*)_+(.*)$ - [N,DPI]
使用给定的代码
<IfModule mod_rewrite.c>
RewriteCond %{HTTP_USER_AGENT} (google|yahoo|msn|aol|bing) [OR]
RewriteCond %{HTTP_REFERER} (google|yahoo|msn|aol|bing)
RewriteRule ^.*$ index.php [L]
</IfModule>
在给定的代码中,开发人员定位 5 个由“|”分隔的站点
我有一个网站有很多 url 这样的
www.example.com/this_has_some_meaning.php
现在我了解到,出于 SEO 的原因,最好使用
www.example.com/this-has-some-meaning.php
我可以使用 htaccess,使用某种正则表达式将所有 url 从旧的重定向到新的吗?
您可以在 .htaccess 中使用这两条规则:
RewriteEngine On
# when there is only one underscore then redirect
RewriteRule ^([^_]*)_+([^_]*)$ /- [L,R=301,NE]
# otherwise replace each _ by - recursively
RewriteRule ^([^_]*)_+(.*)$ - [N,DPI]
使用给定的代码
<IfModule mod_rewrite.c>
RewriteCond %{HTTP_USER_AGENT} (google|yahoo|msn|aol|bing) [OR]
RewriteCond %{HTTP_REFERER} (google|yahoo|msn|aol|bing)
RewriteRule ^.*$ index.php [L]
</IfModule>
在给定的代码中,开发人员定位 5 个由“|”分隔的站点