htaccess SEO url包含样式失败..如何解决这个问题?

时间:2013-10-31 13:28:14

标签: php css apache .htaccess mod-rewrite

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

htaccess的:

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">

1 个答案:

答案 0 :(得分:1)

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

(可选)您可以尝试在页面标题中添加此内容:<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]