2017-05-02 39 views
0

我想從文件中刪除.php後添加URL的斜槓末端。 例如。 www.xyz.com/abc/使用.htaccess從文件中刪除.php後添加URL的斜槓末端

我用下面的.htaccess

RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}\.php -f 
RewriteRule ^(.*)$ $1.php**strong text** 
+0

http://stackoverflow.com/questions/29548556/的可能的複製replace-php-extension-with-slash-using-htaccess –

+0

@DavinderKumar不是一個重複,因爲它是以前的規則使這個不那麼直接 – Lissy

+2

[Htaccess的可能重複:添加/刪除從URL後面的斜槓](http:///stackoverflow.com/questions/21417263/htaccess-add-remove-trailing-slash- from-url) – Pehlaj

回答

1

你可能想這

RewriteEngine On 
# where the .htaccess file is located (public path from document_root) 
RewriteBase /subdir/path/based/on/document_root 


# does not apply to existing directories 
RewriteCond %{REQUEST_FILENAME} !-d 
# rewrite dir-like urls to php script and END rewriting to avoid infinite loop 
RewriteRule (.*)/ $1.php [END] 

# apply to existing files only 
RewriteCond %{REQUEST_FILENAME} -f 
# browser redirect to canonical URL 
RewriteRule (.*)\.php$ $1/ [L,R=301] 
相關問題