dou6495
2016-04-29 14:40
浏览 47
已采纳

如何在本地使用XAMPP设置F3?

I am trying to run a Fat Free PHP project locally with XAMPP from C:\xampp\htdocs\abc My problem is none of my css, images, or links work. I added an .htaccess file:

RewriteEngine On
RewriteBase /abc/
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* /abc/index.php [L,QSA]

It seems to have helped somewhat in that my index.php loads but none of the css nor images load. Also, when I click any links I get 404s, and the url does not route to my /abc directory.

I have tried countless RewriteRules and RewriteConds with no luck.

Also, everything works fine in production so I would like to not change the structure.

Any help on the would be greatly appreciated, thanks.

图片转代码服务由CSDN问答提供 功能建议

我试图在C:\ xampp \ htdocs \ abc My中使用XAMPP在本地运行Fat Free PHP项目 问题是我的css,图像或链接都不起作用。 我添加了一个.htaccess文件:

  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和图像加载。 此外,当我点击任何链接时,我得到404s,并且该URL不会路由到我的 / abc 目录。

我已经尝试了无数的RewriteRules和RewriteConds而没有运气。

此外,一切都在生产中正常工作,所以我不想改变结构。

非常感谢您的任何帮助,谢谢。

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • douzhang7184 2016-05-04 14:48
    已采纳

    Try with this .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]
    
    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • duangu1878 2016-05-02 17:15

    Looks like you're having an issue with paths.

    From your comments, I assume that your assets and links are written like this:

    <link rel="stylesheet" href="/bootstrap.css" />
    <img src="/mypic.png"/>
    <a href="/what/ever.html">click</a>
    

    Those links are absolute (notice the leading /). Which means they are pointing to the server root, so:

    • bootstrap.css resolves to myserver.tld/bootstrap.css
    • mypic.png resolves to myserver.tld/mypic.png
    • etc.

    They are working on your production website probably because the project is hosted on the server root.

    But on your local server, everything is shifted from / to /abc/ which lead to wrong link resolution. So you have two solutions:

    Solution 1

    Preprend all your links with BASE. If you're using the framework template engine, that would give:

    <link rel="stylesheet" href="{{ @BASE }}/bootstrap.css" />
    <img src="{{ @BASE }}/mypic.png"/>
    <a href="{{ @BASE }}/what/ever.html">click</a>
    

    Solution 2

    Inform the browser that all links should be resolved relatively to /abc/ by adding the <base> tag inside your <head> section:

    <base href="http://myserver.tld/abc/">
    

    or

    <base href="/abc/">
    

    NB: the trailing slash is important. The whole string is treated as a prefix for all links.

    Remark

    Those 2 solutions are not 100% equivalent, since the 2nd solution impacts anchor links. Indeed, <a href="#foo"> points to:

    • the current page with the first solution
    • the base URI with the second solution (i.e /abc/#foo)
    评论
    解决 无用
    打赏 举报
  • douyan4470 2016-05-03 11:30

    My advice would be to create a VirtualHost. It impacts other Apache config files, but I assume you just want to recreate the environment locally (where you have a full autonomy and power to customize it), so the code of the application will not need to be changed.

    Open Windows C:\WINDOWS\system32\drivers\etc\hosts file in any text editor, but with admin rights and add the following line:

    127.0.0.1   localcopy.tld
    

    This will tell the system that this host should be handled by a local server.

    Now find your hhtpd-vhosts.conf (it should be in C:\xampp\apache\conf\extra\ directory). Remove hashmark from line with

    NameVirtualHost *.80
    

    and insert the following lines:

    <VirtualHost *:80>
      DocumentRoot C:/xampp/htdocs/abc
      ServerName localcopy.tld
    </VirtualHost>
    

    This will tell Apache that when the request to handle localcopy.tld request, it should find the files in C:/xampp/htdocs/abc directory.

    Finally you need to modify Apache main config file to allow Virtual Hosts. Open the main Apache configuration file, httpd.conf, in a text editor. The file is located in C:\xampp\apache\conf\. Scroll down to the Supplemental configuration section at the end, and locate the following section (around line 500). Remove the hashmark which comments line:

    Include conf/extra/httpd-vhosts.conf
    

    That should do it.

    A more in depth explanation is available here.

    All these will let you access your local copy at http://localcopy.tld.

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题