如何使用htaccess将斜线网址转换为php文件?

时间:2018-10-27 06:00:42

标签: .htaccess

我的网站使用简单的php。我已经从网址中删除了php exentesion,但是我想在网址末尾添加斜杠。我还添加了斜杠,但它给出了404错误。 http://example.com/testpage:有效 http://example.com/testpage/:不起作用

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://example.com/$1/ [L,R=301]

# Run Php without filename extension
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php

# Return 404 if original request is .php
#RewriteCond %{THE_REQUEST} "^[^ ]* .*?\.php[? ].*$"
#RewriteRule .* - [L,R=404]

0 个答案:

没有答案