不带“.php”扩展名的空白页

不带“.php”扩展名的空白页,php,Php,我目前一直在想如何从URL栏中删除.php扩展名。然而,当我删除.php时,它会给我一个空白的白色页面 有人能解释一下为什么会发生这种情况吗 我已经在php.ini中添加了:expose\u php=Off 在我的.htaccess中也得到了这个: 然后开始为URL编写以下内容: php的示例: 没有.php的示例: 这个问题可以通过apache.htaccess配置来解决 RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteR

我目前一直在想如何从URL栏中删除.php扩展名。然而,当我删除.php时,它会给我一个空白的白色页面

有人能解释一下为什么会发生这种情况吗

我已经在php.ini中添加了:expose\u php=Off

在我的.htaccess中也得到了这个:

然后开始为URL编写以下内容:

php的示例:

没有.php的示例:


这个问题可以通过apache.htaccess配置来解决

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

这里的更多信息

我目前在.htaccess中使用这段代码删除扩展名.php,我从未得到一个空白页面

# Rewrite URLs
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]

这是我的htaccess代码,请检查此代码是否适用于您

# Default directory
DirectoryIndex index.php

# ERROR FILES
RewriteEngine On
ErrorDocument 404 /page404.php
ErrorDocument 500 /page500.php

# Remove the need for www in Your URL
RewriteCond %{HTTP_HOST} ^xxxx.pt$ [NC]
RewriteRule (.*) http://www.xxxx.pt/$1 [R=301,L]

# Exclude administrador folder
RewriteRule ^(administrador)($|/) - [L]

# Rewrite URLs
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]

##Expire headers
<IfModule mod_expires.c>
# Enable expirations
ExpiresActive On
# Default directive
ExpiresDefault "access plus 1 month"
# My favicon
ExpiresByType image/x-icon "access plus 1 year"
# Images
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType image/jpg "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
# CSS
ExpiresByType text/css "access plus 1 month"
# Javascript
ExpiresByType text/javascript "access plus 1 month"
</IfModule>

php不仅仅是可选的。省略php后缀的站点将使用Apache或类似工具中的某种复杂重写来实现这一点。通常情况下,它们只传递index.php,但使用服务器指令欺骗路径。另一种方法是创建路径/索引。php@MattFletcher请检查我的最新答案哦,好的。expose_php只隐藏了标题,所以在这个问题的上下文中,不要认为这真的意味着什么。但我不太确定重写规则,也不是我最擅长的技巧。你可以用。没有必要涉及mod_重写,但规则不是重写,是吗?只是404?我想,这本身不会让非.php工作吧?同时道歉,电话和返回按钮继续过早提交!你所有的CSS和JS目录都工作吗?您是否通过main index.php路由URL?然后用URL检查你在哪些页面上?是的,我的所有文件都运行良好,没有任何问题。。。如果你愿意,我可以和你分享我在htaccess文件中的代码,那太好了。谢谢你,丹尼尔。给我发电子邮件:chrisbeckett13@yahoo.co.ukWould你能为我提供你的.htaccess文件吗?
# Rewrite URLs
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]
# Default directory
DirectoryIndex index.php

# ERROR FILES
RewriteEngine On
ErrorDocument 404 /page404.php
ErrorDocument 500 /page500.php

# Remove the need for www in Your URL
RewriteCond %{HTTP_HOST} ^xxxx.pt$ [NC]
RewriteRule (.*) http://www.xxxx.pt/$1 [R=301,L]

# Exclude administrador folder
RewriteRule ^(administrador)($|/) - [L]

# Rewrite URLs
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]

##Expire headers
<IfModule mod_expires.c>
# Enable expirations
ExpiresActive On
# Default directive
ExpiresDefault "access plus 1 month"
# My favicon
ExpiresByType image/x-icon "access plus 1 year"
# Images
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType image/jpg "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
# CSS
ExpiresByType text/css "access plus 1 month"
# Javascript
ExpiresByType text/javascript "access plus 1 month"
</IfModule>