Reputation: 24536
So i'm pretty terrible at RewriteRule
and .htaccess
, and I've been trying to create a RewriteRule which allows me to redirect any request that doesn't already exist in the directory through index.php.
It looks like this at the moment:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?name=$0 [L]
However once I started trying to run ajax requests from a redirected url it breaks and returns the whole redirected page instead of the return data of any script that is in the directory. I'm pretty confused as to how I can make this work. \
What I want to be able to do is to be able to rout every non-real request through index.php and every other request as normal.
Upvotes: 0
Views: 83
Reputation: 135
Your htaccess code is correct. "-f" checks for a valid file and "-d" for a valid directory.
My guess is that you issuing relative ajax requests from an url like /some-dir/another-path/ which is internally rewritten to index.php?name=/some-dir/another-path/. A relative ajax request to ie my-ajax-data.php will be made to /some-dir/another-path/my-ajax-data.php, and not /my-ajax-data.php as you might think. Try using absolute URLs in the ajax requests. Well, it's just a shot in the dark.
Upvotes: 1
Reputation: 6968
You could sneak in another RewriteCond
using a RegEx, in case you can find one (or more) for you normal requests. Something like
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !^*your* *RegEx* *for* *normal* *request*
RewriteRule ^(.*)$ index.php?name=$0 [L]
Upvotes: 1