2013-11-03 169 views
0

當我鍵入domain.com/page.php時,它不會自動更改爲domain.com/page/。另外,在子目錄頁面,如果我跟着一個鏈接到domain.com/sub/1/一切都很好,但如果我在瀏覽器中鍵入它重定向到domain.com/1/.htaccess隱藏文件擴展名並強制結尾斜槓

這是什麼我在.htaccess

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

# 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] 

任何想法我應該做什麼htaccess文件的子目錄和根目錄?我是新來的。

回答

0

更改規則的順序。

試試這個:

RewriteEngine on 

# Forces a trailing slash to be added 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.+?[^/])$ /$1/ [R=301,L] 

# .php ext hiding 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{DOCUMENT_ROOT}/$1.php -f 
RewriteRule ^(.+?)/?$ /$1.php [L] 
相關問題