如何删除 .htaccess 文件中的 .php 扩展名?

我的 URL 像http://example.com/login.php并且我希望它的显示像 http://example.com/login在我的网站第一页是 login.php 而不是 index 所以我在 .htaccess 中设置了这个选项


这是 .htaccess 文件代码


ErrorDocument 403 403.php

ErrorDocument 404 404.php

ErrorDocument 405 405.php

ErrorDocument 501 501.php


RewriteEngine On

RewriteCond %{REQUEST_FILENAME} -s [OR]

RewriteCond %{REQUEST_FILENAME} -l [OR]

RewriteCond %{REQUEST_FILENAME} -d

RewriteRule ^.*$ - [NC,L]

RewriteRule ^.*$ login.php [NC,L]

RewriteCond %{REQUEST_METHOD} !^(GET|POST|HEAD)

RewriteRule .* - [R=501,L]



Options -Indexes

DirectoryIndex login.php


<LimitExcept GET POST>

deny from all

</LimitExcept>

ServerSignature Off 

FileETag None

<IfModule mod_reqtimeout.so>

  RequestReadTimeout header=20-40,MinRate=500 body=20,MinRate=500

</IfModule>




    Header set X-FRAME-OPTIONS SAMEORIGIN 

    Header set Content-Security-Policy: "child-src 'self' allow 'self'; media-src *; img-src *; "

    Header set Access-Control-Allow-Origin: "*"

    Header set X-XSS-Protection "1; mode=block"

    Header set Referrer-Policy "no-referrer | same-origin | origin | strict-origin | no-origin-when-downgrading"

    Header edit Set-Cookie ^(.*)$ $1;HttpOnly;Secure


ABOUTYOU
浏览 143回答 1
1回答

MM们

您可以使用:# To externally redirect without .phpRewriteCond %{THE_REQUEST} \s/+(.+)\.php[\s?] [NC]RewriteRule ^ /%1 [R=301,L,NE]# To internally rewrite to .phpRewriteCond %{REQUEST_FILENAME}.php -fRewriteRule ^ %{REQUEST_URI}.php [L]
打开App,查看更多内容
随时随地看视频慕课网APP