skip to Main Content

I need to know how I change my site url my I try url routing what is not work
my site product url is http://www.shahilibas.in/product.php?p_id=5 and I want seo friendly url like http://www.shahilibas.in/product.php/5
I try this code for url routing

function getCurrentUri()
{
    $basepath = implode('/', array_slice(explode('/',      $_SERVER['SCRIPT_NAME']), 0, -1)) . '/';
    $uri = substr($_SERVER['REQUEST_URI'], strlen($basepath));
    if (strstr($uri, '?')) $uri = substr($uri, 0, strpos($uri, '?'));
    $uri = '/' . trim($uri, '/');
    return $uri;
    echo $uri;
}

2

Answers


  1. You need to add Rewrite Rule to .htaccess file . Create new text file give it name ‘.htaccess’ without quotes .

    In Your .htaccess File Write the Code Below and Press Ctrl + s To save your File

    Options +FollowSymLinks
    RewriteEngine On
    
    RewriteCond %{SCRIPT_FILENAME} !-d
    RewriteCond %{SCRIPT_FILENAME} !-f
    
    
    RewriteRule ^(w+)$ ./serve.php?short=$1
    
    Login or Signup to reply.
  2. You can add following code in your .htaccess file and save

    <IfModule mod_rewrite.c>
    
        Options +FollowSymlinks
    
        RewriteEngine On
        RewriteRule ^([a-zA-Z0-9_-]+)$ products.php?p_id=$1
        RewriteRule ^([a-zA-Z0-9_-]+)/$ products.php?p_id=$1
    
    </IfModule>
    

    Then your url will be like this
    http://www.shahilibas.in/5

    Which is more url friendly. Showing php file in url is not good for SEO.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search