.htaccess - .htaccess 中的 mod_rewrite 替换 .aspx

标签 .htaccess mod-rewrite

我已将网站从 ASP 转换为 php...并且 URL 不再需要扩展名。我想从传入字符串(例如来自搜索引擎)的末尾去掉“.aspx”,然后 302 将它们重定向到不带该扩展名的正确页面,以便我的 mod_rewrite 规则的其余部分可以接管。我该怎么做?

OLD URL:  www.mysite.com/test/page/here.aspx
NEW URL:  www.mysite.com/test/page/here/

谢谢!

最佳答案

将此规则放入根文件夹中的 .htaccess 文件中(在全部重写规则之前,如果有的话):

RewriteRule ^(.+)\.aspx$ http://www.example.com/$1/ [QSA,NC,R=301,L]

这会将 http://www.example.com/test/page/here.aspx 重定向到 http://www.example.com/test/page/here/.

请注意,最好(至少从 SEO/浏览器的角度来看)使用 301 重定向代码(永久重定向)而不是 302(找到/临时重定向)。除非您考虑将网站改回 aspx。

关于.htaccess - .htaccess 中的 mod_rewrite 替换 .aspx,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6603480/

相关文章:

WordPress wp-admin 重定向到 http ://127. 0.0.1/

apache htaccess 位于带有 cpanel/whm 的子目录中

.htaccess - 需要通过使用.htaccess提供禁止的错误403来阻止Google bot,Bing bot和具有空用户代理的客户端

apache - .htaccess 影响其他文件 url

php - mod_rewrite {QUERY_STRING}

php - .htaccess 重定向,除非在 iframe 中

php - 如何使用 htaccess 删除 .php 扩展名

php - htaccess 将别名重定向到主域

apache - 将 HTTP 应用于 Apache 上运行的 HTTPS 网站的一个区域

apache - htaccess 重定向 url 与 anchor 标记