问题原文
原帖链接 · Mantykora 7 · CC BY-SA 4.0
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",
已采纳解答
原帖链接 · MrWhite · CC BY-SA 4.0
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.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
