Php 如何在本地使用XAMPP设置F3?
我正在尝试从C:\XAMPP\htdocs\abc使用XAMPP在本地运行一个无脂肪的PHP项目 我的问题是我的css、图像或链接都不起作用。我添加了一个.htaccess文件:Php 如何在本地使用XAMPP设置F3?,php,apache,.htaccess,xampp,fat-free-framework,Php,Apache,.htaccess,Xampp,Fat Free Framework,我正在尝试从C:\XAMPP\htdocs\abc使用XAMPP在本地运行一个无脂肪的PHP项目 我的问题是我的css、图像或链接都不起作用。我添加了一个.htaccess文件: RewriteEngine On RewriteBase /abc/ RewriteCond %{REQUEST_FILENAME} !-l RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule .* /a
RewriteEngine On
RewriteBase /abc/
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* /abc/index.php [L,QSA]
这似乎对我加载index.php有所帮助,但没有加载css或图像。此外,当我单击任何链接时,我会得到404,并且url不会路由到我的/abc
目录
我尝试过无数次重写规则和条件,但都没有成功
而且,在生产中一切都很好,所以我不想改变结构
非常感谢您在上提供的任何帮助。看起来您在路径方面遇到了问题 根据您的评论,我假设您的资产和链接是这样写的:
<link rel="stylesheet" href="/bootstrap.css" />
<img src="/mypic.png"/>
<a href="/what/ever.html">click</a>
解决方案2
通过在您的
部分中添加
标记,通知浏览器所有链接都应相对于/abc/
进行解析:
<base href="http://myserver.tld/abc/">
或
注意:后面的斜杠很重要。整个字符串被视为所有链接的前缀
备注
这两种解决方案并非100%等效,因为第二种解决方案会影响锚链。实际上,
指向:
- 包含第一个解决方案的当前页面
- 带有第二个解决方案的基本URI(即
)/abc/#foo
- 我的建议是创建一个虚拟主机。它会影响其他Apache配置文件,但我假设您只想在本地重新创建环境(在这里您拥有完全的自主权和定制能力),因此应用程序的代码不需要更改
在任何文本编辑器中打开Windows
C:\Windows\system32\drivers\etc\hosts
文件,但具有管理员权限,并添加以下行:
127.0.0.1 localcopy.tld
这将告诉系统该主机应由本地服务器处理
现在找到您的hhtpd vhosts.conf
(它应该在C:\xampp\apache\conf\extra\
目录中)。将hashmark从带有
NameVirtualHost *.80
并插入以下行:
<VirtualHost *:80>
DocumentRoot C:/xampp/htdocs/abc
ServerName localcopy.tld
</VirtualHost>
应该这样做
更深入的解释
所有这些都将允许您在
http://localcopy.tld
试试这个。htaccess
:
RewriteEngine On
RewriteBase /abc/
# skip all files and directories from rewrite rules below
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule (.+\.(?:gif|png|jpe?g|css))$ /abc/$1 [NC,L]
RewriteRule .* /abc/index.php [L]
+1我知道这可以用HTML
标记解决,但我也很好奇是否有一个纯htaccess解决方案。如果
可以解决它,那么就没有必要想出重写魔法。遗憾的是,这对我不起作用。它不会更改请求URL。
<VirtualHost *:80>
DocumentRoot C:/xampp/htdocs/abc
ServerName localcopy.tld
</VirtualHost>
Include conf/extra/httpd-vhosts.conf
RewriteEngine On
RewriteBase /abc/
# skip all files and directories from rewrite rules below
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule (.+\.(?:gif|png|jpe?g|css))$ /abc/$1 [NC,L]
RewriteRule .* /abc/index.php [L]