1

我正在我的网站上工作,并使用 .htaccess 文件制作了“SEO url”。所以 taht website.eu/contact 等于 website.eu/index.php?file=contact。和 website.eu/case/somthing 等于 website.eu/index.php?file=case&ID=somthing。现在我的问题是,如果地址是 website.eu/contact/ 样式将不会被加载。

访问:

RewriteEngine On

RewriteOptions inherit

Options +FollowSymlinks
Options -Multiviews

RewriteBase /habberdesign

## hide .php extension
## To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}s([^.]+).php [NC]
RewriteRule ^ %1 [R,L,NC]

## To internally forward /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/$ /index.php?file=$2.php&ID=$3
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$ /index.php?file=$2.php&ID=$3

ErrorDocument 404 /index.php?file=404.php

RewriteRule ^countdown /countdown

款式:

<link href="Styles/contact.css" media="screen" rel="stylesheet" type="text/css">
4

1 回答 1

1

确保在您的 css、js、图像文件中使用绝对路径,而不是相对路径。这意味着您必须确保这些文件的路径http://以 slash 或 slash开头/

或者,您可以尝试在页面标题中添加此内容:<base href="/" />

更新:还请记住,RewriteCond仅适用于非常下一个RewriteRule。因此,您的规则应该是这样的:

Options +FollowSymlinks -Multiviews

RewriteBase /habberdesign

## hide .php extension
## To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}s([^.]+).php [NC]
RewriteRule ^ %1 [R,L,NC]

## To internally forward /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/$ /index.php?file=$2.php&ID=$3 [L,QSA]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$ /index.php?file=$2.php&ID=$3 [L,QSA]

ErrorDocument 404 /index.php?file=404.php

RewriteRule ^countdown /countdown [L]
于 2013-10-31T13:31:07.520 回答