[英]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.