问题
I add a error.php page in my web root for all error. Error page redirect by root htaccess rule which redirect well but page css and javascript not work (not loading).
But If I test as: www.myweb.com/error.php its display well format.
My server Apache Version 2.2.27 and PHP Version 5.4.28
my htaccess redirect rule
ErrorDocument 404 /error.php
ErrorDocument 500 /error.php
my full htaccess
# compress text, HTML, JavaScript, CSS, and XML
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
# remove browser bugs
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
Header append Vary User-Agent
suPHP_ConfigPath /home/myweb/public_html/php.ini
# expire 1 week to images, css and javascript files
<FilesMatch ".(swf|ico|css|js)$">
Header set Cache-Control "max-age=604800, public"
</FilesMatch>
#Remove php#
RewriteEngine On
RewriteBase /
# To externally redirect /dir/file.php to /dir/file
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{THE_REQUEST} \s/+(.*?/)?(?:index)?(.*?)\.php[\s?] [NC]
RewriteRule ^ %1%2 [R=302,L,NE]
# To internally forward /dir/file to /dir/file.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC]
RewriteRule ^(.+?)/?$ $1.php [L]
#Remove Userprofile#
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI}\.php -f [NC]
RewriteRule ^(.+?)/?$ $1.php [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\w-]+)/?$ userprofile.php?user=$1 [L,QSA]
#RewriteEngine on#
rewritecond %{http_host} ^www.myweb.com [nc]
rewriterule ^(.*)$ http://myweb.com/$1 [r=301,nc]
#RewriteEngine on#
RewriteCond %{HTTP_HOST} ^111\.111\.11\.111
RewriteRule (.*) http://myweb.com/$1 [R=301,L]
ErrorDocument 404 /error.php
ErrorDocument 500 /error.php
# secure htaccess file
<Files .htaccess>
order allow,deny
deny from all
</Files>
#Disable server signature#
ServerSignature Off
# Fix Rewrite
Options -Multiviews
回答1:
If your css/js is not loading it might be because you're using relative paths.
You can use the base tag in the head section of your html for the path to your css and js files. Then you can use relative paths. e.g
<base href="http://www.example.com/assets/">
or you can put a / in front of your paths to your files.
Otherwise inspect element in the broswer and check the console to see why it's not loading. It give a reason.
来源:https://stackoverflow.com/questions/28612698/errordocument-404-error-php-redirect-but-error-php-page-css-and-js-not-work