我在我的网站上工作,并使用.htaccess文件制作了“ SEO url's”。
因此,网站.eu / contact等于网站.eu / index.php?file = contact。和website.eu/case/somthing等于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">

最佳答案

确保在css,js,图像文件中使用绝对路径,而不要使用相对路径。这意味着您必须确保这些文件的路径以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]

关于php - htaccess SEO URL包含样式失败。如何解决此问题?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19707832/

10-10 22:04