本地 php 站点不在 XAMPP 上运行。可能的 modrewrite 问题?

发布于 2024-11-04 11:28:18 字数 3266 浏览 0 评论 0原文

我使用的是Win 7。我下载了XAMPP 1.7.1。我必须将 http:// localhost/ 更改为 http://localhost:8080/ 因为端口 80 已经很忙。在httpd.conf 中,我将AllowOverride 更改为All。

我运行一个本地网站(php 4.2 和 MySQL)。网站的根目录(位于E:\xampp\htdocs\test)包含一个htaccess文件。

我检查了 php 信息,发现 mod_rewrite 已加载。 htaccess 文件也工作正常并且正在被拾取(我尝试在 htaccess 文件中输入无意义的文本,然后收到服务器错误,确认 htaccess 正常)。

该网站的主页加载正常,但似乎无法获取 css 或 javascript 文件。显示具有直接 url 的主页文本和图像,但不应用任何 css 样式。此外,任何到其他页面的链接都会将我带到http://localhost/xampp/。

我检查了错误日志,它们显示了此错误(有很多这样的行):

[Sun May 01 22:26:57 2011] [error] [client 127.0.0.1] File does not exist: E:/xampp/htdocs/scripts, referer: http://localhost:8080/test/.

htaccess 文件如下(此文件在删除服务器上运行良好):

RewriteEngine On

RewriteBase /

<FilesMatch ".(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
Header set Expires "Thu, 15 Apr 2015 20:00:00 GMT"
Header set Cache-Control "max-age=172800, public, must-revalidate"
</FilesMatch>

Header unset ETag
FileETag None

<IfModule mod_deflate.c>
SetOutputFilter DEFLATE
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png|rar|zip|pdf)$ no-gzip dont-vary
<IfModule mod_headers.c>
Header append Vary User-Agent
</IfModule>
</IfModule>

<IfModule mod_expires.c>

# enable expirations
ExpiresActive On
ExpiresByType image/gif "access plus 7 days"
ExpiresByType image/jpeg "access plus 7 days"
ExpiresByType text/css "access plus 7 days"
ExpiresByType application/x-shockwave-flash "access plus 7 days"
ExpiresByType application/javascript "access plus 7 days"
ExpiresByType text/javascript "access plus 7 days"
ExpiresByType image/png "access plus 7 days"
<FilesMatch "\.(ico|gif|jpg|jpeg|png|flv|pdf)$">
Header append Cache-Control "public"
</FilesMatch>
<FilesMatch "\.(js|css|swf)$">
ExpiresDefault "access plus 7 days"
Header append Cache-Control "public"
</FilesMatch>
</IfModule>

AddEncoding gzip .gz
RewriteCond %{HTTP:Accept-encoding} gzip
RewriteCond %{HTTP_USER_AGENT} !Safari
RewriteCond %{REQUEST_FILENAME}.gz -f
RewriteRule ^(.*)$ $1.gz [QSA,L]

#RewriteRule favicon.ico images/favicon.ico [NC,L]
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
#php_flag magic_quotes_gpc Off

对于为什么会发生这种情况有什么想法吗?

谢谢 瓦西里

更新: 我又玩了一会儿 xampp,最后决定删除阻止端口 80(sql 报告服务)的软件。然后,我在 apache 配置文件中将引用从 localhost:8080 更改为 localhost:80。

不幸的是,这并没有解决问题。

例如,生成的主页将在标题中显示以下内容:

<link href="http://localhost/test/styles/style.css" rel="STYLESHEET" type="text/css" />
<script type="text/javascript" src="http://localhost/test/scripts/jquery.json-2.2.min.js"></script>

链接准确指向硬盘驱动器上 styles.css 和 jquery.js 所在的位置。

同时,图像链接有效,因为图像显示:

<div class="logo"><img src="http://localhost/test/images/logo.png" width="356" height="77" /></div>

网站的配置文件列出了适用于此问题的以下值:

<siteHost>http://localhost/test/</siteHost>
<database>mysql://root:@localhost/prod</database>

不确定下一步要尝试什么。有什么想法吗?

谢谢 瓦西利

I am using Win 7. I downloaded XAMPP 1.7.1. I had to change the http:// localhost/ to http://localhost:8080/ as port 80 was already busy. In httpd.conf I changed AllowOverride to All.

I run a local website (php 4.2 and MySQL). The root directory of the website (located in E:\xampp\htdocs\test) contains an htaccess file.

I checked the php info to see that mod_rewrite is loaded. The htaccess file is also working correctly and is being picked up (I tried to enter nonsense text in the htaccess file and got a server error after that which confirms the htaccess is fine).

The website's home page loads fine, but it does not seem to pick up css or javascript files. The home page text and images having a direct url are shown, but any css styling isn't applied. In addition, any links to other pages just take me to http:// localhost/xampp/.

I checked the error logs and they show this error (there are a lot of lines like this):

[Sun May 01 22:26:57 2011] [error] [client 127.0.0.1] File does not exist: E:/xampp/htdocs/scripts, referer: http://localhost:8080/test/.

The htaccess file is as follows (this file works great on the remove server):

RewriteEngine On

RewriteBase /

<FilesMatch ".(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
Header set Expires "Thu, 15 Apr 2015 20:00:00 GMT"
Header set Cache-Control "max-age=172800, public, must-revalidate"
</FilesMatch>

Header unset ETag
FileETag None

<IfModule mod_deflate.c>
SetOutputFilter DEFLATE
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png|rar|zip|pdf)$ no-gzip dont-vary
<IfModule mod_headers.c>
Header append Vary User-Agent
</IfModule>
</IfModule>

<IfModule mod_expires.c>

# enable expirations
ExpiresActive On
ExpiresByType image/gif "access plus 7 days"
ExpiresByType image/jpeg "access plus 7 days"
ExpiresByType text/css "access plus 7 days"
ExpiresByType application/x-shockwave-flash "access plus 7 days"
ExpiresByType application/javascript "access plus 7 days"
ExpiresByType text/javascript "access plus 7 days"
ExpiresByType image/png "access plus 7 days"
<FilesMatch "\.(ico|gif|jpg|jpeg|png|flv|pdf)$">
Header append Cache-Control "public"
</FilesMatch>
<FilesMatch "\.(js|css|swf)$">
ExpiresDefault "access plus 7 days"
Header append Cache-Control "public"
</FilesMatch>
</IfModule>

AddEncoding gzip .gz
RewriteCond %{HTTP:Accept-encoding} gzip
RewriteCond %{HTTP_USER_AGENT} !Safari
RewriteCond %{REQUEST_FILENAME}.gz -f
RewriteRule ^(.*)$ $1.gz [QSA,L]

#RewriteRule favicon.ico images/favicon.ico [NC,L]
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
#php_flag magic_quotes_gpc Off

Any ideas of why this is happening?

Thanks
Vasiliy

Update:
I played with xampp a little more and finally decided to remove the software which blocked port 80 (sql reporting services). I then changed the reference from localhost:8080 to localhost:80 in the apache config file.

Unfortunately, that didn't fix the issue.

For example, the generated home page would show the following in the header:

<link href="http://localhost/test/styles/style.css" rel="STYLESHEET" type="text/css" />
<script type="text/javascript" src="http://localhost/test/scripts/jquery.json-2.2.min.js"></script>

The links point exactly to the location on my hard-drive where the styles.css and jquery.js are located.

At the same time a link to an image works because the image shows up:

<div class="logo"><img src="http://localhost/test/images/logo.png" width="356" height="77" /></div>

The config file for the website lists the following values which are applicable to this issue:

<siteHost>http://localhost/test/</siteHost>
<database>mysql://root:@localhost/prod</database>

Not sure what to try next. Any ideas?

Thanks
Vaciliy

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

断念 2024-11-11 11:28:18

您可以尝试在每个页面的标题中添加基本 URL:

<head>
<base href="http://localhost:8080/" />
</head>

我个人在使用 mod_rewrite 时会使用完整路径而不是相对路径,那么您将不需要上述解决方案。

You could try adding a base URL to the header of each page:

<head>
<base href="http://localhost:8080/" />
</head>

I would personally use full paths rather than relative ones when using mod_rewrite, then you wont need the above solution.

拥醉 2024-11-11 11:28:18

确保您的路径包含前导斜杠。

不等于

检查这是否有帮助。

Make sure your paths include a leading slash.

<link href="css/style.css" />

is not equivalent to

<link href="/css/style.css" />

or

<link href="./css/style.css" />

Check whether this helps.

一曲爱恨情仇 2024-11-11 11:28:18

我在这里添加这个是为了贡献或帮助OP,因为我还不能添加评论。

Vasiliy 检查您网站的目录中是否有任何 htaccess 文件,不久前我对图像和 css 文件也遇到了同样的问题,这是对 htaccess 文件的 mod 重写。

I'm adding this here in order to contribute or help the OP since i can't add comments yet.

Vasiliy check if you have any htaccess file in the directory of your site, i had the same issue a while ago with images and css files and it was a mod rewrite on an htaccess file.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文