PDA

View Full Version : URL rewriting and Javascript


Sk84
12-11-2008, 01:16 PM
Hi everyone!

I'm coding an AJAX site, and I'm using SEO URLs with mod_rewrite. I've managed to make it so that, when a user requests "comics/t/201", he's redirected to "index.php?comic_strip&title=t&strip=201". It was also easy enough to enhance the .htaccess so that the CSS files, the JS scripts and the images are all pointed to correctly (i.e., using paths relative to index.php rather than to comics/t/201).

The problems begin when I try to launch an AJAX request. Here's an example:
function showLoginForm()
{
var url = "src/backend/showLoginForm.php";
var params = "";
var callback = function(http)
{
BetterInnerHTML(element('overlay'), http.responseText);
}
postAjax(url, params, callback);
}

When I use actual URLs (or rewritten URLs without "virtual directories", such as "register.html" which is redirected to "register.php") it all works nice and clean. When I am on "comics/t/201" for example, instead, the XHR (it's hidden inside the postAjax() function) returns a 404 error code.

I understand it's because it is now looking for "comics/t/src/backend/etcetc", while the actual file is in "src/backend". I couldn't find any help about this problem. I don't think it can't be done - it should be something that's done in any SEO site.

Can anyone please shred some light on me?

TuNiX
12-11-2008, 04:08 PM
i think i understand what your trying to say... can you use the site URL instead of just launching the request in your current directory? instead of starting here "/" start here "http://www.mywesite.com/"?

Sk84
12-11-2008, 06:05 PM
Tunix, your solution works. In fact, it suffices to write the URL as "/src/backend...". It would still be interesting, though, to see how to rewrite the URLs passed in Javascript.

TuNiX
12-11-2008, 06:23 PM
wow seriously? haha i totally didn't understand a word of your post but i do a ton of Linux command line writing, visual basic programming, and website work but when i saw that you were having a directory problem i remembered that in all of the stuff i have done most problems arose when i was trying to launch commands form the wrong directory and the only way to make those things work would be to punch in the whole command, location, or url.