使用.htaccess从文件中删除.php后添加URL的斜杠结尾

时间:2017-05-02 07:27:46

标签: php .htaccess

我想在从文件中删除.php之后添加url的斜杠结尾。 对于前者www.xyz.com/abc /

我使用了以下.htaccess

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

1 个答案:

答案 0 :(得分: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]