Using Seo User Friendly in PHP

Using SEO-friendly links

Stackoverflow does something similar to your me.com/john-adams-123 option, except more like me.com/123/john-adams where the john-adams part actually has no programmatic meaning. The way you're proposing is slightly better because the semantic-content-free numeric ID is farther to the right in the URL.

What I would do is store a unique slug (these SEO-friendly URL components are generally called slugs) in the user table and do the number append thing when necessary to get a unique one.

Make SEO Friendly URL in Php with help of .htaccess

With your shown samples, could you please try following. Please make sure to clear your browser cache before testing your URLs.

RewriteEngine ON
##Rule for handling non-existing pages here to index.php file.
RewriteRule ^(A1-13-05-2021)/?$ index.php?title=$1 [QSA,NC,L]



Generic Rules: In case you want to make it Generic rules then try following rules only.

RewriteEngine ON
##Rule for handling non-existing pages here to index.php file.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(A1-\d{2}-\d{2}-\d{4})/?$ index.php?title=$1 [QSA,NC,L]

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

SEO friendly url using php

You can essentially do this 2 ways:

The .htaccess route with mod_rewrite

Add a file called .htaccess in your root folder, and add something like this:

RewriteEngine on
RewriteRule ^/Some-text-goes-here/([0-9]+)$ /picture.php?id=$1

This will tell Apache to enable mod_rewrite for this folder, and if it gets asked a URL matching the regular expression it rewrites it internally to what you want, without the end user seeing it. Easy, but inflexible, so if you need more power:

The PHP route

Put the following in your .htaccess instead:

FallbackResource index.php

This will tell it to run your index.php for all files it cannot normally find in your site. In there you can then for example:

$path = ltrim($_SERVER['REQUEST_URI'], '/');    // Trim leading slash(es)
$elements = explode('/', $path); // Split path on slashes
if(count($elements) == 0) // No path elements means home
ShowHomepage();
else switch(array_shift($elements)) // Pop off first item and switch
{
case 'Some-text-goes-here':
ShowPicture($elements); // passes rest of parameters to internal function
break;
case 'more':
...
default:
header('HTTP/1.1 404 Not Found');
Show404Error();
}

This is how big sites and CMS-systems do it, because it allows far more flexibility in parsing URLs, config and database dependent URLs etc. For sporadic usage the hardcoded rewrite rules in .htaccess will do fine though.

*****Copy this content from URL rewriting with PHP**

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]

Most effective way to code SEO friendly URLs?

You could get the whole query string as one paramter.

RewriteRule ^([^.]+)$ index.php?url=$1 [QSA,L]

Then you can split the string with php and convert the different parameters into an array to do whatever you like with.

SEO Friendly URL

I'm not sure why people are being so deliberately obtuse here...

What you are looking for is mod_rewrite, an apache module for URL rewriting.

In your .htaccess file (you might need to make it) put:

<IfModule mod_rewrite.c>
RewriteEngine on

RewriteRule ^blog\/([0-9]+)\/.*$ /blog.php?post=$1 [L]
</IfModule>

This means when you go to /blog/10/any-old-bit-of-text/ behind the scenes it is identical to if you visited /blog.php?post=10.

The ([0-9]+) bit is called a regular expression (or regex), and matches any number. The .* means match anything. The ^ anchors to the start of the query and the $ anchors to the end. slashes (/) are escaped as \/.

php : SEO friendly urls

Sample rules for .htaccess (once you make sure mod_rewrite is enabled):

  RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php?page=$1 [L]

These rules match any URL that isn't an already existing file and passes it to your script.

Sanitizing urls using php for seo friendly

I use this sweet function to generate SEO friendly URL

function url($url) {
$url = preg_replace('~[^\\pL0-9_]+~u', '-', $url);
$url = trim($url, "-");
$url = iconv("utf-8", "us-ascii//TRANSLIT", $url);
$url = strtolower($url);
$url = preg_replace('~[^-a-z0-9_]+~', '', $url);
return $url;
}


Related Topics



Leave a reply



Submit