Php CSS,includes&;图像与mod_重写、相对路径和基本目录 我想要什么
Php CSS,includes&;图像与mod_重写、相对路径和基本目录 我想要什么,php,css,.htaccess,mod-rewrite,url-rewriting,Php,Css,.htaccess,Mod Rewrite,Url Rewriting,http://example.com/index.php?lang=en&page=main 应该看起来像http://example.com/en/main 图像、包含和CSS应具有相对路径 网站应该仍然可以通过原始链接访问(如果可能的话?) 我所拥有的 我读了很多关于htaccess、mod_重写、BasePath等的书。 我尝试了很多组合,但总有一个组合不起作用 大多数情况下,CSS没有加载(错误路径:/en/style.CSS),或者旧格式的链接不再工作 我当前的结构: /incl
http://example.com/index.php?lang=en&page=main
应该看起来像http://example.com/en/main
/en/style.CSS
),或者旧格式的链接不再工作
我当前的结构:
/incl
|incl1.php
|incl2.php
/img
|img1.png
|img2.png
index.php
style.css
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]*)/([^/]*)$ /index.php?lang=$1&page=$2 [L,NC]
<link href="style.css" rel="stylesheet" type="text/css" />
<base href="http://example.com/">
...
<img src="img/img1.png" />
...
<?php include('incl/incl1.php'); ?>
background-image: url(img/img2.png);
我当前的.htaccess:
/incl
|incl1.php
|incl2.php
/img
|img1.png
|img2.png
index.php
style.css
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]*)/([^/]*)$ /index.php?lang=$1&page=$2 [L,NC]
<link href="style.css" rel="stylesheet" type="text/css" />
<base href="http://example.com/">
...
<img src="img/img1.png" />
...
<?php include('incl/incl1.php'); ?>
background-image: url(img/img2.png);
我的当前站点:
/incl
|incl1.php
|incl2.php
/img
|img1.png
|img2.png
index.php
style.css
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]*)/([^/]*)$ /index.php?lang=$1&page=$2 [L,NC]
<link href="style.css" rel="stylesheet" type="text/css" />
<base href="http://example.com/">
...
<img src="img/img1.png" />
...
<?php include('incl/incl1.php'); ?>
background-image: url(img/img2.png);
编辑:什么不起作用:
/incl
|incl1.php
|incl2.php
/img
|img1.png
|img2.png
index.php
style.css
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]*)/([^/]*)$ /index.php?lang=$1&page=$2 [L,NC]
<link href="style.css" rel="stylesheet" type="text/css" />
<base href="http://example.com/">
...
<img src="img/img1.png" />
...
<?php include('incl/incl1.php'); ?>
background-image: url(img/img2.png);
未找到CSS和favicon。可能是因为它们是在
/en/style.css
我需要什么
正确组合
- .htaccess
(我需要它吗?我没有通过尝试获得更好的结果)RewriteBase
RewriteCond
重写规则
- 场地
或
或src=“style.css”
src=“/style.cs”
或
- CSS
或背景图片:url(img/img2.png)
背景图像:url(/img/img2.png)代码>
- 我是否应该将所有图像和css放在
子文件夹中?我该如何使用它/static
多谢各位 首先,您需要了解重写规则无法修复
php include
,因为这种情况发生在php内部,而控件甚至不会因此返回php
现在要修复css/js/images
最好的选择是使用绝对链接。如果出于某种原因,您无法将其添加到页面标题中:
然而,也有一种方法来修正这些规则
Options +FollowSymLinks
RewriteEngine On
# fix css/js/images link
RewriteRule ^[a-z]{2}/(.+?\.(?:jpe?g|gif|bmp|png|tiff|css|js))$ /$1 [L,NC,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]*)/([^/]*)$ /index.php?lang=$1&page=$2 [L,NC,QSA]
那么到底是什么不起作用呢?没有找到CSS和favicon。可能是因为它们是在
/en/style.css
中假定的。我是否可能只需要在
中的相对路径中添加/
前缀?我试过了,看起来很有效,但我仍然需要测试一切。这怎么可能?为什么只在头上?