Simone Simone - 1 year ago 69
Ajax Question

.htaccess, how can I remove pattern from url?

I would like to clean my urls from this:


My code is as follow:


RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^welcome/([^/]+)/?$ index.php?a=welcome&filter=$1 [NC,QSA,L]
RewriteRule ^track/([^/]+)/?$ index.php?a=track&filter=$1 [NC,QSA,L]
RewriteRule ^(([^/]+)+)(/([^/]{0,32})(/.+)?)?$ index.php?a=$1&q=$3 [L,QSA]

But if I use the 2nd example (the url without
) via Ajax it returns "undefined".

I tried the Ajax call with this link button

<a href="'.$this->url.'/track/'.$id.'" rel="loadpage">Click Here</a>

I supposed it's undefined because in my requests I get the
parameter in PHP as

So my question is: why it doesn't work on Ajax?

Here is my

$(function() {
$("body").on("click", "a[rel='loadpage']", function(e) {
// Get the link location that was clicked
pageurl = $(this).attr('href');
// Replace the path of the url from index to the path with raw content
var custom = pageurl;
var custom = custom.replace(baseUrl+'/track', 'page.php?a=track');
var custom = custom.replace(baseUrl+'/', 'page.php?a=welcome');
// Request the page
$.ajax({url:custom,success: function(data) {
// Show the content
// Stop the loading bar
// Scroll the document at the top of the page
// Reload functions

// Store the url to the last page accessed
if(pageurl != window.location){
window.history.pushState({path:pageurl}, '', pageurl);
return false;

isn't my forte, so any help would be much appreciated.

Thanks in advance.

Answer Source

You can use this JS code to send your AJAX call:

var custom = pageurl.replace(baseUrl+'/track/', '/page.php?a=track&id=');

// Request the page
$.ajax({url:custom,success: function(data) {
   // ...
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download