我遇到一个问题,即 google 已将一些具有错误 URL 的页面编入索引。
他们索引的 URL 是:
http://www.example.com/user/emp.php
和 HTML 网址:
http://www.example.com/login.html
我需要它重定向到:
http://www.example.com/user/emp
和 HTML 网址:
http://www.example.com/login
这是我的 .htaccess 文件
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteRule ^([^\.]+)$ $1.html [NC,L]
最佳答案
首先检查是否存在以.html
或.php
结尾的适当目标,然后重写为该URL
RewriteEngine On
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^([^\.]+)$ $1.html [L]
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([^\.]+)$ $1.php [L]
关于php - htaccess 从 url 中删除 .php 和 .html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42901265/