开发者

php:Mod rewrite giving me hard times finding base address.. need help

im new to Mod_rewrite but problem is it ruins all my ajax and php

i use windows.location object to get current location for javascript example:

var str = location.pathname;
str=str.slice(0,str.lastIndexOf('/'));

problem that this never works since i used mod_rewrite. my .htaccess

Options +FollowSymLinks
RewriteEngine on
RewriteRule ^cars/([^/]+)/?$ profiles.php?carname=$1 [L]

can some body lead me to way to fix this. ? also i face same problem with lading all imgs and css/.js but i heard i can write condition on .htaccess to only redirect .php !,

I need a way to find base address for ajax calls, and other way to find base address for ph开发者_开发技巧p.


the problem is that you are redirecting all your url to a php file and it breaks all the other assets, including css and js.

Solution:

Use a rewrite condition. this way it only redirects if the file or directory doesn't exist.

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^cars/([^/]+)/?$ profiles.php?carname=$1 [L]

the first line is : if file doesn't exist the second is: if directory doesn't exist the there will be a redirect.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜