【问题标题】:Specific url to work with and without .php using .htaccess使用 .htaccess 使用和不使用 .php 的特定 url
【发布时间】:2016-11-22 15:48:27
【问题描述】:

我正在尝试配置一个特定的 url 以使用和不使用 .php 扩展名。

例如想以两种方式访问​​下面的url:

example.com/manage.php

example.com/manage

这是我当前的 .htaccess:

<IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteBase /

        # Removes index.php from ExpressionEngine URLs
        RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
        RewriteCond %{REQUEST_URI} !/library/.* [NC]
        RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]

        # Directs all EE web requests through the site index file
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ^(.*)$ /index.php?/$1 [L,QSA]
        # RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>

【问题讨论】:

    标签: regex apache .htaccess mod-rewrite expressionengine


    【解决方案1】:

    您可以在重定向规则下方插入重写规则:

    RewriteEngine On
    RewriteBase /
    
    # Removes index.php from ExpressionEngine URLs
    RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
    RewriteCond %{REQUEST_URI} !/library/.* [NC]
    RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]
    
    # add .php extension to specific URIs
    RewriteRule ^(manage)/?$ $1.php [L,NC]
    
    # Directs all EE web requests through the site index file
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /index.php?/$1 [L,QSA]
    

    【讨论】:

      猜你喜欢
      • 2023-03-20
      • 1970-01-01
      • 2016-09-15
      • 2017-06-12
      • 2017-08-13
      • 2023-04-08
      • 2014-06-22
      • 2016-12-05
      • 2012-04-29
      相关资源
      最近更新 更多