将网站移动到子目录-获取图像/css路径以工作



我在一个子目录中有一个网站,但所有的图像、链接和CSS路径都是这样设置的:

"/images/error.png"或"/help.html"或"/css/styles/stylesheet.css"

我已经尝试了一百万种不同的.htaccess方法,并尝试将基本href标记设置为domain.com/subfolder.

我似乎什么都做不了!

此外:这个系统中有数百个文件,所以我不能手动将所有路径更改为相对路径。

当您编写:Ive got a website in a subdirectory时,我假设您也将所有图像、css等移动到了子目录中。

如果是这样的话,您可以使用一个简单的RewriteRule来管理它。使用以下代码在DOCUMENT_ROOT下创建.htaccess:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
# If the request is for a valid directory
RewriteCond %{REQUEST_FILENAME} -d [OR]
# If the request is for a valid file
RewriteCond %{REQUEST_FILENAME} -f [OR]
# if this is a link
RewriteCond %{REQUEST_FILENAME} -l
# forward to subdirectory if it is not already subdirectory
RewriteRule ^((?!subdirectory/).*)$ subdirectory/$1 [L,NC]

使用相对路径(http://webdesign.about.com/od/beginningtutorials/a/aa040502a.htm)

所以如果你的图像在中

/SubFolder/Images/ 

以及您查看文件

/SubFolder/index.htm
Images/fileName.png

会起作用的。

最新更新