【发布时间】:2014-02-11 01:08:30
【问题描述】:
我想要什么
-
http://example.com/index.php?lang=en&page=main应该看起来像
http://example.com/en/main - 图像、包含和 CSS 应具有相对路径
- 网站应该仍然可以通过原始链接访问(如果可能?)
我有什么
我已经阅读了很多关于 htaccess、mod_rewrite、BasePath 等的内容。 我尝试了很多组合,但总有一种情况不起作用。
大多数情况下 CSS 未加载(路径错误:/en/style.css)或旧格式的链接不再起作用。
我目前的结构:
/incl
|incl1.php
|incl2.php
/img
|img1.png
|img2.png
index.php
style.css
我当前的 .htaccess:
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'); ?>
我目前的 CSS:
background-image: url(img/img2.png);
编辑:什么不起作用:
未找到 CSS 和网站图标。可能是因为它们被假定为/en/style.css
我需要什么
正确的组合
-
.htaccess
-
RewriteBase(我需要那个吗?我尝试并没有得到更好的结果) RewriteCondRewriteRule
-
-
网站
-
<base href="http://example.com/">或<base href="/">? -
src="style.css"或src="/style.cs"? -
<?php include('incl/incl1.php'); ?>或<?php include('/incl/incl1.php'); ?>?
-
-
CSS
-
background-image: url(img/img2.png);或background-image: url(/img/img2.png);?
-
我应该把我所有的图像和 css 放在
/static子文件夹中吗?我该如何使用它?
非常感谢!
【问题讨论】:
-
那么到底是什么不起作用?
-
未找到 CSS 和网站图标。可能是因为它们被假定为
/en/style.css。我是否可能只需要在<head>中的相对路径中添加/前缀?刚刚尝试过,它似乎工作,但我仍然需要测试一切。这怎么可能?为什么只在头部?
标签: php css .htaccess mod-rewrite url-rewriting