Php 平面链接的mod#u rewrite的行为类似于';在子目录中
我正试图在Php 平面链接的mod#u rewrite的行为类似于';在子目录中,php,apache,.htaccess,mod-rewrite,Php,Apache,.htaccess,Mod Rewrite,我正试图在.htaccess中创建一个mod\u rewrite规则集,这样我就可以创建一些指向页面功能的平面链接 当用户输入时:http://example.com/where/location 我想重定向到:http://example.com/index.php?where=location 我目前正在使用: RewriteEngine on RewriteRule ^where/([^/.]+)/?$ /index.php?where=$1 除了在index.php中找不到css、JS
.htaccess
中创建一个mod\u rewrite
规则集,这样我就可以创建一些指向页面功能的平面链接
当用户输入时:http://example.com/where/location
我想重定向到:http://example.com/index.php?where=location
我目前正在使用:
RewriteEngine on
RewriteRule ^where/([^/.]+)/?$ /index.php?where=$1
除了在index.php
中找不到css、JS和图像链接之外,哪种方法有效?这就好像服务器是从不存在的/where/location
子目录向上提供index.php服务一样
这就是正在发生的事情吗?是否有一种方法可以将服务器包装成从其在根目录中的实际位置开始提供index.php的相对链接?服务器端与此无关。您实际上是从
/where/location
为站点提供服务的;这个URL在内部被重写是无关紧要的。如果您使用的是CSS文件的相对路径,那么浏览器将根据其所在的当前URL解析这些路径。最好的策略通常是使用包含文件的绝对路径,例如:
/css/style.css
而不是
css/style.css
我想这是一个很好的实践——现在只需要检查我所有的源代码。