【发布时间】:2025-12-16 12:05:02
【问题描述】:
我创建了一个简单的网站,其中一些页面 url 的格式为“*.php”。
我想将我的网址 /home.php 设为 /home。我可以在.htaccess 文件中执行此操作吗?
我在这里添加我的代码
<files campus_config.ini>
order allow,deny
deny from all
Allow from 127.0.0.1
</files>
<files student.ini>
order allow,deny
deny from all
Allow from 127.0.0.1
</files>
<FilesMatch (variables|mysql)\.php>
order allow,deny
deny from all
</FilesMatch>
RewriteEngine on
RewriteCond %{THE_REQUEST} \s/+(?:index)?(.*?)\.php[\s?] [NC]
RewriteRule ^ /%1 [R=301,L,NE]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC]
RewriteRule ^(.+?)/?$ /$1.php [L]
示例网址: localhost/test/campus/login.php(test是一个文件夹,campus是我的项目文件夹,.htaccess文件在我的项目文件夹中)
【问题讨论】:
-
但是当我在 .htaccess 文件中尝试相同时,它给了我一个错误“/home is not found on this server”,请帮助
-
一个解决方案(虽然不是最好的):httpd.apache.org/docs/2.2/mod/core.html#forcetype
-
@Linblow ,我没有得到解决方案,你能解释一下你提到的,谢谢你的回复:)
-
@Vishnu 你在运行 Apache 还是 IIS?
-
@LIUFA,我正在使用 Apache