简体   繁体   English

使用htaccess将php查询字符串转换为seo url

[英]Convert php query string to seo url using htaccess

Currenlty I am getting all data from MySQL database using following PHP query string: Currenlty我正在使用以下PHP查询字符串从MySQL数据库获取所有数据:

ccroipr.php?id=201801161516084475

from this link: 从此链接:

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

Now 现在

I want the URL should be ccroipr-201801161516084475 我希望网址应为ccroipr-201801161516084475

From this link 从这个连结

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

currenlty, Using following .htaccess rules: currenlty,使用以下.htaccess规则:

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

It's accepting this URL: 它接受以下URL:

ccroipr?201801161516084475

Not this one: 不是这个:

ccroipr-201801161516084475

How can I do this using .htaccess? 我如何使用.htaccess做到这一点?

Update: 更新:

Ajax/jQuery Code Ajax / jQuery代码

$('#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 );
        }
    });
});

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]

也许您可以尝试一下,为我工作。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM