我如何使用的.htaccess隐藏的.php URL扩展?如何使用、htaccess、URL、php

2023-09-02 09:36:33 作者:浅忆°

我想要的东西,把我的的.htaccess 文件,将隐藏的.php 文件扩展我的PHP文件,因此要www.example.com/dir/somepage~~V会告诉他们www.example.com/dir/somepage.php。

对此有任何可行的解决方案?我的网站使用HTTPS,如果在所有重要的。

这是我的.htaccess的时刻:

  RewriteEngine叙述上

的RewriteCond%{} SERVER_PORT 80
重写规则^(。*)$ https://www.example.com/$1 [R,L]

ErrorDocument的404 /error/404.php

的RewriteCond%{} REQUEST_FILENAME -f .PHP
的RewriteCond%{REQUEST_URI}!/ $
重写规则(。*)$ 1  .PHP [L]
 

解决方案 怎么让IIS支持PHP的.htaccess文件

使用这种code在你的.htaccess下DOCUMENT_ROOT:

 选项+了FollowSymLinks -MultiViews
#开启mod_rewrite的上
RewriteEngine叙述上
的RewriteBase /

#要外部重定向/dir/foo.php到/ DIR /富
的RewriteCond%{THE_REQUEST} ^ [AZ] {3,}  S([^。] +)。PHP [NC]
重写规则^%1 [R,L,NC]

##在内部重定向/ DIR /富到/dir/foo.php
的RewriteCond%{} REQUEST_FILENAME -f .PHP [NC]
重写规则^%{REQUEST_URI}的.php [L]
 

I want something to put in my .htaccess file that will hide the .php file extension for my php files, so going to www.example.com/dir/somepage would show them www.example.com/dir/somepage.php.

Is there any working solution for this? My site uses HTTPS, if that matters at all.

This is my .htaccess at the moment:

RewriteEngine On

RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]

ErrorDocument 404 /error/404.php

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule (.*) $1.php [L]

解决方案

Use this code in your .htaccess under DOCUMENT_ROOT:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}s([^.]+).php [NC]
RewriteRule ^ %1 [R,L,NC]

## To internally redirect /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME}.php -f [NC]
RewriteRule ^ %{REQUEST_URI}.php [L]