【问题标题】:How To Decorate URL using .htaccess and Remove .php extension如何使用 .htaccess 装饰 URL 和删除 .php 扩展名
【发布时间】:2016-07-10 06:56:09
【问题描述】:

这是当前 URL,我想从 URL 中删除“/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]

这是我的目录结构

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

【问题讨论】:

    标签: php .htaccess


    【解决方案1】:

    试试这个

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

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

    希望对你有所帮助。

    【讨论】:

      猜你喜欢
      • 2019-03-03
      • 1970-01-01
      • 2022-01-21
      • 2014-03-04
      • 2011-04-30
      相关资源
      最近更新 更多