删除.php exetension后遇到错误

问题描述 投票:0回答:2

这是我删除 .php 扩展名后的 .htaccess 代码。我面临这个错误


错误请求 您的浏览器发送了此服务器的请求 无法理解。

 DirectorySlash On
    RewriteCond %{THE_REQUEST} ^GET\s([^.]+)\.php\?id=([^&\s]+)\s [NC]
    RewriteRule ^ %1/%2? [R,L]
    # Redirect external .php requests to extensionless url
    RewriteCond %{THE_REQUEST} ^(.+)\.php([#?][^\ ]*)?\ HTTP/
    RewriteRule ^(.+)\.php$ https://%{HTTP_HOST}/$1/ [L,NC]

编辑:

.htaccess 位于根目录内。

原网址是这样的:cloud9cumulus.com/shield payments/view/login.php

php .htaccess
2个回答
0
投票

试试这个,

Options -MultiViews

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^shieldpayments/view/([\w-]+)$ shieldpayments/view/$1.php [L]

此规则足以删除当前网址的 .php 扩展名,并在尝试之前删除与此相关的其他规则。


0
投票

问题的解决方案终于出来了

<IfModule mod_rewrite.c>
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{THE_REQUEST} \s/+(.+?)\.php[\s?] [NC]
RewriteRule ^ /%1 [R=302,NE,L]
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{THE_REQUEST} /index\.php [NC]
RewriteRule ^(.*)index\.php$ /$1 [L,R=302,NC,NE]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]

</IfModule>
© www.soinside.com 2019 - 2024. All rights reserved.