从URL中删除.php并强制使用尾部斜杠/

时间:2011-09-23 16:11:56

标签: .htaccess mod-rewrite

我想使用.htaccess mod_rewrite从我的所有文件中删除.php并强制使用尾随斜杠/。但是,这只会导致我收到服务器错误。

1 个答案:

答案 0 :(得分:2)

您想映射:

http://sampledomain.ext/index/ -> http://sampledomain.ext/index.html

使用以下.htaccess

 RewriteEngine On
 RewriteCond %{REQUEST_URI} ! \.php$ #Avoid real php page, do what you want with them
 RewriteCond %{REQUEST_URI} /$       #Ensure a final slash
 RewriteRule ^(.*)$ $1.php           #Add your extension

Tx给David Wolever写了相同的东西1

如果我可以发表意见,那么强制/最后一个文件是否有点奇怪?

相关问题