modrewrite issue - 404 error

可紊 提交于 2019-12-13 01:43:14

问题


I have this url

http://sites.com/driver.php?n=spa

I made it look like this

http://sites.com/driver/spa

here is .htaccess code I am using..

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^driver([^/]*)$ driver.php?n=$1 [L,QSA]

it's working but for instance all my files including scripts and stylesheets are not working because it's adding to /driver to all urls like this example

http://sites.com/style.css

to

http://sites.com/driver/style.css 

.. I can avoid by writing the full script and stylesheet urls but is there any other way? I can do this but I have more than 40 script and stylesheet urls and it will take me time to rewrite them all with the full url.


回答1:


Reason of this problem is use of relative links on CSS/js/image resources. To fix this issue you can sdd this in your page's HTML header:

<base href="/" />

This week tell browser's to append a / everyone it finds a relative path resource in the page.



来源:https://stackoverflow.com/questions/27280890/modrewrite-issue-404-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!