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 ?
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.
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
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.