[英]htaccess remove .php and .html from url
我遇到了一个问题,即Google用错误的URL为某些页面编制了索引。
他们正在索引的URL是:
http://www.example.com/user/emp.php
和HTML URL:
http://www.example.com/login.html
我需要它重定向到:
http://www.example.com/user/emp
和HTML URL:
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]
将其替换为htacess文件中的此代码。
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
例如,请从您正在调用的所有链接中删除.html和.php。
<a href="index.html">Home</a>
To
<a href="index">Home</a>
确保已经安装了mod_rewrite模块,检查phpinfo();
的输出phpinfo();
功能确认。 我认为以下.htaccess
很好。 将htaccess放在应用程序的根目录中。
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteRule ^([^\.]+)$ $1.html [NC,L]
阅读本关于如何在PHP安装的mod_rewrite
# Remove .html-extension from url
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^([^\.]+)$ $1.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.