Page 1 of 1

Create friendly seo link

Posted: 27 Jun 2016, 16:00
by mluci12
Hello!
When i create PHP apps i create link like domain.com/page?variable=&variable2 , but this is not seo friendly.
How can i make link like: domain.com/variable/variable2 and GET variable value.

Create friendly seo link

Posted: 27 Jun 2016, 17:57
by Admin
Hi,
You can create friendly seo links with mod_rewrite in the .htaccess file.
For example:

Code: Select all

Options +FollowSymLinks
RewriteEngine On

RewriteRule ^([A-z0-9_\-]+)/([A-z0-9_\-]+)$ page.php?v1=$1&v2=$2 [NC,L]
Then, in html add the friendly link:

Code: Select all

<a href="//domain.com/some_val/other_val" title="Text">Text</a>
And, in php you can use a code like this to get the "some_val" and "other_val":

Code: Select all

$v1 = isset($_GET['v1']) ? $_GET['v1'] :'';
$v2 = isset($_GET['v2']) ? $_GET['v2'] :'';
To learn about this, just look on the net for: " mod_rewrite htaccess ".
- You need to know /learn a little about RegExp (regular expressions) to write the expression to "RewriteRule" according to the link you want.