开发者

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

开发者 https://www.devze.com 2023-03-16 20:11 出处:网络
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:

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

精彩评论

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