我在 Oracle Virtualbox 上使用 LAMP。一切都运行良好,直到我进入 /etc/apache2/sites-enabled/ 并更改了虚拟主机文件中的某些内容。我没有备份,也不确定我做了什么。documentRoot 正在被找到并正在index.php
加载。但是,我的所有 CSS 和 Javascript 文件都返回 404,所以我基本上得到了一个带有文本和图像的无样式页面。我的所有 CSS 和 JS 都位于/var/www/retirenetDev/retirenet/web/
“web”是文档根目录的位置,如下所示。所有内容都被正确地重写为 index.php,但即使是静态 css 文件呢?
我只是根据访问日志中看到的内容进行猜测。我确信我删除的代码与重写有关。我删除了几行代码,然后网站就崩溃了。
这是我的虚拟主机:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName retirenet.dev
DocumentRoot /var/www/retirenetDev/retirenet/web/
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/retirenetDev/retirenet/web/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
RewriteEngine On
RewriteCond $1 !^(fckeditor/)
RewriteRule ^/(.*)$ /index.php/$1 [L]
Alias /fckeditor "/home/open/retirenet/web/fckeditor/"
AddOutputFilterByType DEFLATE text/html text/plain
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
CustomLog /var/log/apache2/access.log combined
</VirtualHost>
下面是加载页面时的 Apache 访问日志:
10.0.0.120 - - [20/Dec/2015:10:33:34 -0500] "GET /c/fonts.x6x.css/ HTTP/1.1" 404 3228 "http://retirenet.dev/" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36"
10.0.0.120 - - [20/Dec/2015:10:33:34 -0500] "GET /s/jquery.scrollTo-1.4.0-min.js/ HTTP/1.1" 404 3228 "http://retirenet.dev/" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36"
10.0.0.120 - - [20/Dec/2015:10:33:34 -0500] "GET /i/spinner.gif HTTP/1.1" 301 380 "http://retirenet.dev/" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36"
10.0.0.120 - - [20/Dec/2015:10:33:34 -0500] "GET /s/jquery.serialScroll-1.2.1-min.js/ HTTP/1.1" 404 3228 "http://retirenet.dev/" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36"
10.0.0.120 - - [20/Dec/2015:10:33:34 -0500] "GET /i/top100_new.jpg HTTP/1.1" 301 383 "http://retirenet.dev/" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36"
10.0.0.120 - - [20/Dec/2015:10:33:34 -0500] "GET /i/close.gif HTTP/1.1" 301 378 "http://retirenet.dev/" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36"
10.0.0.120 - - [20/Dec/2015:10:33:34 -0500] "GET /i/spinner.gif/ HTTP/1.1" 404 3228 "http://retirenet.dev/" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36"
10.0.0.120 - - [20/Dec/2015:10:33:34 -0500] "GET /i/top100_new.jpg/ HTTP/1.1" 404 3228 "http://retirenet.dev/" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36"
10.0.0.120 - - [20/Dec/2015:10:33:34 -0500] "GET /i/close.gif/ HTTP/1.1" 404 3228 "http://retirenet.dev/" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36"
127.0.0.1 - - [20/Dec/2015:10:33:42 -0500] "OPTIONS * HTTP/1.0" 200 126 "-" "Apache/2.2.22 (Ubuntu) (internal dummy connection)"
10.0.0.120 - - [20/Dec/2015:10:52:04 -0500] "GET / HTTP/1.1" 200 14167 "http://retirenet.dev/" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36"
10.0.0.120 - - [20/Dec/2015:10:52:04 -0500] "GET /c/fonts.x6x.css HTTP/1.1" 301 383 "http://retirenet.dev/" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36"
10.0.0.120 - - [20/Dec/2015:10:52:04 -0500] "GET /s/jquery.center.js HTTP/1.1" 301 386 "http://retirenet.dev/" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36"
10.0.0.120 - - [20/Dec/2015:10:52:04 -0500] "GET /c/new_responsive.x6x.css HTTP/1.1" 301 392 "http://retirenet.dev/" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36"
10.0.0.120 - - [20/Dec/2015:10:52:04 -0500] "GET /c/fonts.x6x.css/ HTTP/1.1" 404 3228 "http://retirenet.dev/" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36"
10.0.0.120 - - [20/Dec/2015:10:52:04 -0500] "GET /c/style.x6x.css HTTP/1.1" 301 382 "http://retirenet.dev/" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36"
10.0.0.120 - - [20/Dec/2015:10:52:04 -0500] "GET /s/jquery-2.1.4.min.js HTTP/1.1" 301 389 "http://retirenet.dev/" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36"
10.0.0.120 - - [20/Dec/2015:10:52:04 -0500] "GET /c/listings.x6x.css HTTP/1.1" 301 386 "http://retirenet.dev/" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36"
10.0.0.120 - - [20/Dec/2015:10:52:04 -0500] "GET /s/retscripts.x7x.js HTTP/1.1" 301 386 "http://retirenet.dev/" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36"
10.0.0.120 - - [20/Dec/2015:10:52:04 -0500] "GET /c/listings.x6x.css/ HTTP/1.1" 404 3228 "http://retirenet.dev/" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36"
10.0.0.120 - - [20/Dec/2015:10:52:04 -0500] "GET /s/jquery.serialScroll-1.2.1-min.js HTTP/1.1" 301 401 "http://retirenet.dev/" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106
知道问题可能出在哪里吗?apache 错误日志中没有错误。我看到的唯一错误是在我的 Firebug 中:
"NetworkError: 404 Not Found - http://retirenet.dev/s/retscripts.x7x.js/"
/s/rets...x7x.js/
"NetworkError: 404 Not Found - http://retirenet.dev/s/jquery.center.js/"
/s/jque...ter.js/
"NetworkError: 404 Not Found - http://retirenet.dev/s/jquery.scrollTo-1.4.0-min.js/"
/s/jque...min.js/
"NetworkError: 404 Not Found - http://retirenet.dev/s/jquery.serialScroll-1.2.1-min.js/"
/s/jque...min.js/
"NetworkError: 404 Not Found - http://retirenet.dev/i/top100_new.jpg/"
/i/top1...ew.jpg/
"NetworkError: 404 Not Found - http://retirenet.dev/s/jquery.cookie.js/"
/s/jque...kie.js/
"NetworkError: 404 Not Found - http://retirenet.dev/i/spinner.gif/"
/i/spinner.gif/
"NetworkError: 404 Not Found - http://retirenet.dev/c/new_responsive.x6x.css/"
/c/new_...6x.css/
"NetworkError: 404 Not Found - http://retirenet.dev/s/jquery-2.1.4.min.js/"
/s/jque...min.js/
"NetworkError: 404 Not Found - http://retirenet.dev/c/listings.x6x.css/"
/c/list...6x.css/
"NetworkError: 404 Not Found - http://retirenet.dev/c/fonts.x6x.css/"
/c/fonts.x6x.css/
"NetworkError: 404 Not Found - http://retirenet.dev/c/style.x6x.css/"
/c/style.x6x.css/
"NetworkError: 404 Not Found - http://retirenet.dev/i/close.gif/"
/i/close.gif/
"NetworkError: 404 Not Found - http://retirenet.dev/s/jquery.center.js/"
/s/jque...ter.js/
"NetworkError: 404 Not Found - http://retirenet.dev/s/jquery.scrollTo-1.4.0-min.js/"
/s/jque...min.js/
"NetworkError: 404 Not Found - http://retirenet.dev/s/jquery.serialScroll-1.2.1-min.js/"
/s/jque...min.js/
"NetworkError: 404 Not Found - http://retirenet.dev/s/jquery.cookie.js/"
/s/jque...kie.js/
"NetworkError: 404 Not Found - http://retirenet.dev/s/retscripts.x7x.js/"
所以基本上,我可以正常浏览网站。来自数据库的所有数据都已正确加载。所有页面都未设置样式且损坏,因为 JS 和 CSS 未加载。谢谢!
更新:这是我的新主机虚拟主机文件,其中更新了重写条件。仍然一样。不起作用:
<VirtualHost *:80>
ServerName retirenet.dev
DocumentRoot /var/www/retirenetDev/retirenet/web/
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/retirenetDev/retirenet/web/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
RewriteEngine On
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</VirtualHost>
答案1
这个问题的答案如下:
RewriteRule ^/(c|s)/(\w+)(.x[0-9]+x)(.css|.js)?$ /$1/$2$4 [L]
这行代码处理我的 css 和 javscript 文件的重写。我没有意识到我正在为我的 css 和 js 文件调用一个常量,以帮助查看者获取最新版本。我需要为其设置一个正则表达式模式。以下是其中一个引用的示例:
<link rel="stylesheet" type="text/css" href="/c/style.x<?=CSS_VER?>x.css" />