Shibbir
Shibbir

Reputation: 409

Convert php query string to seo url using htaccess

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 );
        }
    });
});

Upvotes: 1

Views: 319

Answers (2)

anubhava
anubhava

Reputation: 784998

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]

Upvotes: 2

Wocugon
Wocugon

Reputation: 586

Maybe you can try this, worked for me.

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

Upvotes: 0

Related Questions