【问题标题】:htaccess .php extension removal: Getting internal error while accessing url with trailing slashhtaccess .php 扩展删除:访问带有斜杠的 url 时出现内部错误
【发布时间】:2019-09-09 11:16:22
【问题描述】:

我正在尝试从我的网址中删除 .php 扩展名,使其对用户友好。

我正在尝试重写此网址:example.com/about.php 作为 example.com/about 和 example/about/

所以,我在这里尝试获取带有 & 不带斜杠的 url。

另外,我试图在使用 .php 访问时返回 404 错误

一切都很顺利。但是,在访问带有斜杠的 url 时出错。像这样的:example/about/

请帮我解决问题。

提前谢谢你。

我尝试了其他代码,修改了“/?$”,但不起作用。

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}\.php -f 
RewriteRule ^(.*)$ $1.php

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

【问题讨论】:

    标签: php .htaccess


    【解决方案1】:

    试试这些

    <IfModule mod_rewrite.c>
    
        RewriteEngine On
        Options +MultiViews
    
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule ^([^\.]+)$ $1.php [NC,L]
    
    </IfModule>
    

    【讨论】:

      猜你喜欢
      • 2011-12-11
      • 1970-01-01
      • 2012-04-15
      • 2012-06-17
      • 2018-01-29
      • 2014-10-22
      • 2011-03-02
      • 2017-05-13
      • 1970-01-01
      相关资源
      最近更新 更多