2013-08-26 69 views
1

我想使它所以請求http://www.domain.tld/folder/filename.php得到301重定向到http://www.domain.tld/folder/filename(即沒有PHP)和我有一些困難,這樣做。301重定向* .PHP非 - *。PHP

這裏是我的.htaccess:

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_URI} !\.php$ 
RewriteRule (.*) $1.php [L] 

RewriteRule (.*)\.php $1 [L,R=301] 

首先重寫規則工程,我所期待。其次...不是很多。

書面請求http://www.domain.tld/folder/filename.php得到301重定向到http://www.domain.tld/home/username/public_html/folder/filename

如果我更改最後重寫規則做/$1而不是$1我被引導到http://www.domain.tld/filename,而不是http://www.domain.tld/folder/filename

任何想法?

謝謝!

回答

2

保持你的.htaccess像這樣隱藏.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[\s?] [NC] 
RewriteRule^%1 [R=301,L] 

# To internally forward /dir/foo to /dir/foo.php 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{DOCUMENT_ROOT}/$1.php -f 
RewriteRule ^(.+?)/?$ $1.php [L]