如何使用.htaccess和Remove .php扩展名来装饰URL

时间:2016-03-23 05:28:14

标签: php .htaccess

这是当前网址,我想从网址中删除“/public/index.php”,然后如何编写.htaccess

  

块引用   http://localhost/Fresh/public/index.php

的.htaccess

<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
    Options -MultiViews
</IfModule>

RewriteEngine On

# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]

# Handle Front Controller...


RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule ^ index.php [L]

这是我的目录结构 enter image description here

如何重写.htaccess以删除子目录并装饰URL。

1 个答案:

答案 0 :(得分:0)

试试这个

RewriteEngine On
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule !.*\.php$ %{REQUEST_FILENAME}.php [QSA,L]

OR

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

希望它会对你有所帮助。