skip to Main Content

I have a website that contains URLs in this format www.example.com/jobs.php?id=123456

All URLs are stored in a database.

I want to make SEO friendly URLs (example:www.example.com/this-is-my-first-job)

I have built this website in php.

is it possible to generate SEO friendly urls from the current format without modifying the .htaccess file ?

2

Answers


  1. Chosen as BEST ANSWER

    I am saying simple.

    When someone post a job to my website, I store all information in database and generate a unique key (let say 123456) and populate on a single page based on the URL that would be www.somewebsite.com?mypage?id=123456 Now I want the existing url to be changed. I want that when user hit this URL, he will automatically be redirected to some different URL that is stored in database too.


  2. As far i understand your question, first you need .htaccess for SEO friendly URL. Now, for example www.example.com/jobs.php?id=123456 is an URL and you want to redirect the user to www.example.com/this-is-my-first-job which is stored in database.
    Let see,

    if(isset($_GET['id'])){
       //get the slug from database against id
       header("Location: www.example.com/".$slug);
     }
    

    How to get the id from slug?

    write in .htaccess

    Options +FollowSymlinks
    RewriteEngine on
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule (.*)$ index.php?slug=$1 [QSA,NC,L]
    

    now in PHP

        if(isset($_GET['slug'])){
         //get the id from database against slug
         }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search