2012-05-22 148 views
0

我想通過htaccess文件從url中刪除.php文件。例如home.php到家 我在htaccess文件中使用以下重寫規則。使用htaccess文件刪除文件擴展名.php

RewriteRule ^(([^/]+/)*[^.]+)$ /$1.php [L] 

我也想分配登錄作爲索引。 我該如何改變它。

+0

那麼什麼是不工作? – Ansari

回答

0
RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}\.html -f 
RewriteRule ^(.*)$ $1.html 
# Replace html with your file extension, eg: php, htm, asp 

要在URL 的末尾添加一個斜槓(例如:http://www.example.com/about-us/http://www.example.com/about-us.html

RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}\.html -f 
RewriteRule ^([^/]+)/$ $1.html 

# Forces a trailing slash to be added 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$ 
RewriteRule (.*)$ /$1/ [R=301,L] 
2

這是你可以用它來隱藏PHP擴展的代碼:

Options +FollowSymLinks -MultiViews 
# Turn mod_rewrite on 
RewriteEngine On 
RewriteBase/

## hide .php extension 
# To externally redirect /dir/foo.php to /dir/foo 
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC] 
RewriteRule^%1 [R,L,NC] 

## To internally redirect /dir/foo to /dir/foo.php 
RewriteCond %{DOCUMENT_ROOT}/$1.php -f 
RewriteRule ^(.*?)/?$ $1.php [L,NC] 
相關問題