1

Currenlty I am getting all data from MySQL database using following PHP query string:

ccroipr.php?id=201801161516084475

from this link:

<a href="ccroipr.php?id=201801161516084475">Profile</a>

Now

I want the URL should be ccroipr-201801161516084475

From this link

<a href="ccroipr-201801161516084475">Profile</a>

currenlty, Using following .htaccess rules:

RewriteEngine On
RewriteRule /(.*)/(.*)/$ ccroipr.php?id=$1

It's accepting this URL:

ccroipr?201801161516084475

Not this one:

ccroipr-201801161516084475

How can I do this using .htaccess?

Update:

Ajax/jQuery Code

$('#register').submit(function( e ) {
    e.preventDefault();        
    var formData = $('form').get(0);    
    $.ajax({
        type : 'POST', 
        dataType : 'html',
        data: new FormData(formData),
        url : 'process/ccroipr-cat-p.php', 
        cache:false,
        contentType: false,
        processData: false,
        beforeSend : function () {
            $('#result').html( 'Please wait...' );
            $('#registerButton').prop('disabled', true);
        },
        success : function ( result ) {            
            $('#registerButton').prop('disabled', false);
            $('#result').html( result );
        }
    });
});
1
  • 1
    “It's accepting this URL: ccroipr?201801161516084475 - that likely has nothing to do with your rewrite attempt at all, but is just the result of MultiViews finding the PHP file of the same name, ccroipr.php. “Not this one: ccroipr-201801161516084475 - and considering that your pattern requires a slash at the front, in the middle and at the end, this now surprises you how exactly …? Commented Jan 16, 2018 at 8:32

2 Answers 2

1

You can use this rule using - as delimiter:

Options -MultiViews
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?[^-]*-(.+?)/?$ ccroipr.php?id=$1 [L,QSA]
Sign up to request clarification or add additional context in comments.

3 Comments

Object not found if I go to this url: ccroipr-201801161516084475
Hi, something happening. If I place the .htaccess file in our site root directory then jQuery/Ajax call is not working but If I remove it then it's working fine. Do you know why?
Needed to skip real files and directories from this rule.
0

Maybe you can try this, worked for me.

RewriteRule ^site/([a-zA-Z])$ ccroipr.php?id=$1

Comments

Your Answer

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