How to Create Friendly Url in PHP

Create dynamic SEO friendly url in core PHP

Add this code in your .htaccess

RewriteEngine OnRewriteRule ^([a-zA-Z0-9-/]+).html$ product.php?pr_url=$1RewriteRule ^([a-zA-Z0-9-/]+)$ category.php?cat_url=$1

Create SEO Friendly URLs from _GET query

You have to redirect your orignal uri to the new uri , add the followng before your existing rule :

RewriteEngine on
RewriteCond %{THE_REQUEST} /(?:index\.php)?\?a=search&query=(.+)\sHTTP [NC]
RewriteRule ^ /search/%1? [NE,L,R]

Make a friendly URL with 2 parameters on PHP with Apache

Have this .htaccess inside /demo_webpages_project/:

Options -MultiViews
RewriteEngine on
RewriteBase /demo_webpages_project/

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/?$ download.php?project_name=$1&version=$2 [L,QSA]

Creating user friendly URL with directory

Have your rules like this in /profile/.htaccess:

RewriteEngine On 
RewriteBase /profiles/

RewriteCond %{THE_REQUEST} /\?username=([^&\s]+) [NC]
RewriteRule ^ %1? [L,R=302]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ index.php?username=$1 [L,QSA]
  • Your rule was only matching [0-9]+ after /profile/, which won't match sam.
  • For adding .php you should check it's existence first.

Technique to create user friendly URLs

This can be achieved with the Apache mod_rewrite RewriteEngine. An example .htaccess:

RewriteEngine On
RewriteRule ^/profile/username/([\d]+)$ profile.php?id=$1

php create friendly url

If I have interpreted correctly (?) you wish to convert the urls you harvest from the "webservice" call and convert them to seo friendly links?

The following is not jQuery but seems to parse the data and return the url in the format you want.

if( typeof( 'getPairs' )!='function' ){
function getPairs(d,z) {
var a = new Object();
var pr = d.split(z);
for( var i=0;i<pr.length;i++ ) {
var p = pr[i].indexOf('=');
if (p == -1) continue;
var n = pr[i].substring(0,p);
var v = pr[i].substring(p+1);
a[n] = unescape(v);
}
return a;
}
}
if( typeof( 'prepareurl' )!='function' ){
function prepareurl(u){
var p=u.split('?')[0].split('.')[0];
var q=u.split('?')[1];
var t=[p];
var o=getPairs( q, '&' );
for( k in o )t.push( o[k] );
return t.join('/');
}
}

alert( prepareurl( '/trip.php?id_trip=1234&continent=oceania' ) );

will return `/trip/1234/oceania`


Related Topics



Leave a reply



Submit