1

I have an ajax file that is called when someone begins to type in search bar. I have recently been cleaning up my urls and removing file extentions adding trailing slashes, since then my ajax file doesnt appear to load anymore. can anyone help? here my htaccess so far

Options +FollowSymlinks
Options +Indexes
RewriteEngine on


RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^([^/]+)/$ $1.php
RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.php

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]

RewriteCond %{THE_REQUEST} ^[A-Z]+\ /[^.#?\ ]+\.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^([^.]+)\.php$ /$1 [R=301,L]
Sumurai8
  • 20,333
  • 11
  • 66
  • 100
AJFMEDIA
  • 2,093
  • 6
  • 29
  • 52
  • I believe RewriteCond's only apply to the rule directly below them, so if your AJAX request is being made to a path two directories deep, and a directory exists this could explain it. What address are you making the AJAX request to, and what is the actual URL it should be accessing? – Peter O'Callaghan Aug 28 '10 at 13:12
  • the ajax requests /include/get-content.php and this is the url of the file: www.lovelakedistrict.com/include/get-content.php is this what you meant? – AJFMEDIA Aug 28 '10 at 13:39
  • @ajfmedia - Does it work if you remove that last condition and rule? It's possible that the the 301 redirect messes up the request, so if that's the problem, it shouldn't be too hard to ignore that rule just for the files you access with AJAX requests. (but I didn't want to post an answer related to that without knowing that was the actual problem) – Tim Stone Aug 28 '10 at 14:08
  • yes it works fine when I remove the last condition and rule. Do you know hot to ignor that rule for the ajax request? Thanks tim and cags – AJFMEDIA Aug 28 '10 at 14:28

1 Answers1

2

Assuming that your AJAX requests go to the /includes folder, and your normal pages do not, we can modify your rules a bit so that they look like this (including Cags' comment about the RewriteCond):

Options +FollowSymlinks
Options +Indexes

RewriteEngine on

# We'll do the redirect first, so no other rules get in the way
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([^.#?\ ]+)\.php([#?][^\ ]*)?\ HTTP/
# Make sure the request didn't start with "includes"
RewriteCond %1 !^includes/
RewriteRule ^([^.]+)\.php$ /$1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/$ $1.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.php

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]

I also think that you either wanted /? at the end of the rules in the center block, or /$1/ as the replacement on the rule in the first block, so that the redirect from /page.php to /page gets interpreted correctly after the first redirect (I think right now you'll get redirected twice, once by the first block, and again by the last block).

Community
  • 1
  • 1
Tim Stone
  • 19,119
  • 6
  • 56
  • 66
  • great thankyou so much. Works perfect. if you search for something now, you get filtered search results :) http://www.lovelakedistrict.com – AJFMEDIA Aug 28 '10 at 15:14