为什么我无法访问本地主机 XAMPP 上的某些页面或目录?
Why I can't access some pages or directories on my localhost XAMPP?
首先,我已经在网上搜索了,但找不到解决方案。
所以,这是我对我的网站所做的以及我的分步问题:
- 我的 XAMPP
中有一个项目 运行
(将 localhost 编辑为 127.0.0.1:80)
(将 htdocs 编辑到我的工作区文件夹)
- 我尝试为我的网站设置一个
htaccess
文件,只是为了删除 php 和 html 扩展名:
这里可以看到它的内容:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ .php [NC,L]
RewriteRule ^([^\.]+)$ .html [NC,L]
- 我还有 Visual Studio 的
Live Server
插件,它生成随机数量的 端口 。 (可能会干扰?)
- 有时我可以访问
index.php
有时我不能。
- 我一直无法访问
/icons/...
目录。
我真的需要一个认真的帮助,否则我可能会失去我的项目:(
提前向求解器致谢<3
您发布的重写配置毫无意义。重写引擎应该如何决定使用哪条规则?你希望它能神奇地猜到吗?
看看这个,找出不同之处:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^\.]+)$ .php [NC,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^([^\.]+)$ .html [NC,L]
更好的变体是:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [END]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^ %{REQUEST_URI}.html [END]
一般性评论:您应该始终倾向于在实际的 http 服务器的主机配置中实施此类规则。分布式配置文件(“.htaccess”)有很多缺点,只有在没有其他选择的情况下才应该使用它们(阅读:如果您使用的是廉价的托管服务提供商并且无法访问真实配置)。
首先,我已经在网上搜索了,但找不到解决方案。
所以,这是我对我的网站所做的以及我的分步问题:
- 我的 XAMPP 中有一个项目 运行
(将 localhost 编辑为 127.0.0.1:80)
(将 htdocs 编辑到我的工作区文件夹)
- 我尝试为我的网站设置一个
htaccess
文件,只是为了删除 php 和 html 扩展名:
这里可以看到它的内容:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ .php [NC,L]
RewriteRule ^([^\.]+)$ .html [NC,L]
- 我还有 Visual Studio 的
Live Server
插件,它生成随机数量的 端口 。 (可能会干扰?) - 有时我可以访问
index.php
有时我不能。 - 我一直无法访问
/icons/...
目录。
我真的需要一个认真的帮助,否则我可能会失去我的项目:(
提前向求解器致谢<3
您发布的重写配置毫无意义。重写引擎应该如何决定使用哪条规则?你希望它能神奇地猜到吗?
看看这个,找出不同之处:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^\.]+)$ .php [NC,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^([^\.]+)$ .html [NC,L]
更好的变体是:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [END]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^ %{REQUEST_URI}.html [END]
一般性评论:您应该始终倾向于在实际的 http 服务器的主机配置中实施此类规则。分布式配置文件(“.htaccess”)有很多缺点,只有在没有其他选择的情况下才应该使用它们(阅读:如果您使用的是廉价的托管服务提供商并且无法访问真实配置)。