最近有人问我是否可以使我的朋友服务器地址更加用户友好。他当前的网址如下所示:
http://wwww.example.com/site/index.php?page=home
http://wwww.example.com/site/index.php?page=about/john
http://wwww.example.com/site/index.php?page=portfolio/concept-art/2013
他希望他们看起来像这样
http://wwww.example.com/site/home
http://wwww.example.com/site/about/john
http://wwww.example.com/site/portfolio/concept-art/2013
我以为这很简单,所以我在重写后写了这个。
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !/(admin|css|fonts|ico|include|js)/
RewriteRule ^([^_]*)$ index.php?page=$1 [L]
这似乎适用于像
http://wwww.example.com/site/home
但是对于这样的事情
http://wwww.example.com/site/about/john
CSS或JS均不会加载。因此,我现在通过将所有文件都设置为绝对路径来解决该问题,但我担心我的朋友将添加一个新插件或其他内容,而忘记了他必须将其设置为绝对路径。
我的问题
我可以更改或添加我的htaccess文件以使css和js文件以相对路径加载吗?如果是这样,我该怎么办?
最好使用以下规则:
RewriteEngine On
RewriteBase /site/
RewriteCond %{REQUEST_FILENAME} !/(admin|css|fonts|ico|include|js)/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+?)/?$ index.php?page=$1 [L,QSA]
然后,对于css / js / images,最好在css,js,图像文件中使用绝对路径,而不要使用相对路径。这意味着您必须确保这些文件的路径以http://
或斜杠开头/
。
另外,您可以尝试将其添加到页面标题中:
<base href="/" />
要么
<base href="http://domain.com/site/" />
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句