如何解决如何忽略 URL 末尾的 URL
original: https://www.example.com/video/12345/name-of-the-video/
有时用户或网络爬虫会以不同的方式编写 URL:
https://www.example.com/video/12345/name-of-the-video/65485/
https://www.example.com/video/12345/
https://www.example.com/12345/
我希望所有 3 个网址都重定向(转发)到原始网址:
https://www.example.com/video/12345/name-of-the-video/
我当前的 htaccess 规则是:
RewriteRule ^video/([0-9]+)/([^/]+)/$ view_video.PHP?id=$1&dir=$2 [L,QSA]
RewriteRule ^video/([0-9]+)/$ view_video.PHP?id=$1&dir=fake [L,QSA]
解决方法
您能否尝试以下内容,根据您显示的样本编写。请确保在测试您的网址之前清除浏览器缓存。
RewriteEngine ON
##To rewrite URL https://www.example.com/12345/
RewriteRule ^([0-9]+)/?$ view_video.php?id=$1&dir=fake [NC,L]
##To rewrite URL https://www.example.com/video/12345/
RewriteRule ^video/([0-9]+)/?$ view_video.php?id=$1&dir=fake [NC,L]
##To rewrite URL https://www.example.com/video/12345/name-of-the-video/65485/
RewriteRule ^video/([0-9]+)/([\w-]+)/[0-9]+/?$ view_video.php?id=$1&dir=$2 [R=301,NC]
RewriteCond %{REQUEST_URI} ^/view_video\.php [NC]
RewriteCond %{QUERY_STRING} id=([^&]*)&dir=(.*) [NC]
RewriteRule ^(.*) video/%1/%2 [R=301,L]
##To rewrite URL https://www.example.com/video/12345/name-of-the-video/
RewriteRule ^video/([0-9]+)/([\w-]+)/?$ view_video.php?id=$1&dir=$2 [NC,L]
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。