Htaccess won't work with ajax/php
.htaccess files are extremely useful in many cases for users who either do not have root permissions or for users who simply aren't comfortable in making changes in their web server's configuration file. Trying to debug .htaccess not working isn't always the easiest thing to do, however, hopefully by checking the discuss below mentioned about htaccess, ajax, , , .htaccess common problems as well as the troubleshooting tips, you'll have a better grasp on what you may have to modify to get your .htaccess file running smoothly.Problem :Sending ajax request by jquery doesn't working with htaccess. Works without htaccess.
product_configurator.php -> fetch_data_p.php
$.ajax({
url:"fetch_data_p.php",
method:"POST",
htaccess RewriteRule ^(product_configurator).html/(d+)&(d+)$ $1.php?prometheus_id=$2&id=$3 [L]
- it works
http://mantykora.cleoni.com:8080/photo_gallery/public/product_configurator.html?prometheus_id=10082&id=30 - did not work
http://mantykora.cleoni.com:8080/photo_gallery/public/product_configurator.html/10082&30
Why is this happening?
@MrWhite SOULUTION
$.ajax({
url:"http://localhost/photo_gallery/public/fetch_data_p.php",
method:"POST",
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.
Currently:
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.
Comments
Post a Comment