Sending ajax request by jquery doesn't working with htaccess. Works without htaccess.

product_configurator.php -> fetch_data_p.php


htaccess RewriteRule ^(product_configurator)\.html/(\d+)&(\d+)$ $1.php?prometheus_id=$2&id=$3 [L]

  1. it works http://mantykora.cleoni.com:8080/photo_gallery/public/product_configurator.html?prometheus_id=10082&id=30
  2. did not work http://mantykora.cleoni.com:8080/photo_gallery/public/product_configurator.html/10082&30

Why is this happening?


  • Why do you want to rewrite your AJAX URLs like this? It isn't standard practice to do so. AJAX calls are usually easier to make with query parameters. The URLs don't need to be "clean" for SEO. Commented Nov 5, 2020 at 13:35
  • @Stephen I wanted to add at the end rewrite map category and product name /cotton&cotton-produkt. I don't know if it's good practice to use ajax with htaccess. Is it possible at all. Commented Nov 5, 2020 at 13:47
  • The not working should have nothing to do with AJAX. It isn't common to try to rewrite the PATH_INFO to QUERY_STRING within the same script. I'm not sure if it would solve your problem but have you tried rewriting a different URL like /photo_gallery/public/p/10082&30 to /photo_gallery/public/product_configurator.html?prometheus_id=10082&id=30? Commented Nov 5, 2020 at 13:52
  • @Stephen Added RewriteRule ^(product_configurator)\.html/p/(\d+)&(\d+)$ $1.php?prometheus_id=$2&id=$3 [L] same no answer Commented Nov 5, 2020 at 14:05
  • How about a rule like RewriteRule ^photo_gallery/public/p/(\d+)&(\d+)$ photo_gallery/public/product_configurator\.html\.php?prometheus_id=$1&id=$2 that doesn't have path conflicts in it? Commented Nov 5, 2020 at 15:13

1 Answer 1


The problem would seem to be that you are using a relative client-side URL to make the AJAX request and since you are using a URL at a different path depth fetch_data_p.php is not found.

The AJAX request for fetch_data_p.php is relative to the visible URL in the browser. You need to make this URL root-relative (starting with a slash). eg. /photo_gallery/public/fetch_data_p.php.


When at the URL /photo_gallery/public/product_configurator.html?prometheus_id=10082&id=30, your AJAX call to fetch_data_p.php resolves to /photo_gallery/public/fetch_data_p.php and it works.

However, when at the URL /photo_gallery/public/product_configurator.html/10082&30, your AJAX call to fetch_data_p.php resolves to /photo_gallery/public/product_configurator.html/fetch_data_p.php which naturally fails - 404 Not Found.

This doesn't really have anything to do with the URL rewrite itself in .htaccess, except for the fact the client-side URL is different and importantly, a different path depth. The AJAX call itself is not being rewritten.

  • Every time you write back to me, it enlightens me and everything becomes clear:) url:"http://localhost/photo_gallery/public/fetch_data_p.php", Commented Nov 9, 2020 at 7:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.