[英]Redirect URLs without .htaccess
I have a website that contains URLs in this format www.example.com/jobs.php?id=123456
我有一个网站,其中包含以下格式的URL:
www.example.com/jobs.php?id=123456
All URLs are stored in a database. 所有URL都存储在数据库中。
I want to make SEO friendly URLs (example: www.example.com/this-is-my-first-job
) 我想制作SEO友好的URL(例如:
www.example.com/this-is-my-first-job
)
I have built this website in php. 我已经用php建立了这个网站。
is it possible to generate SEO friendly urls from the current format without modifying the .htaccess
file ? 是否可以在不修改
.htaccess
文件的情况下从当前格式生成SEO友好的url?
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. 当有人将工作发布到我的网站时,我将所有信息存储在数据库中并生成一个唯一的密钥(假设为123456),并基于URL填充到单个页面上,该URL为
www.somewebsite.com?mypage?id=123456
现在我希望更改现有网址。 I want that when user hit this URL, he will automatically be redirected to some different URL that is stored in database too. 我希望当用户点击该URL时,他也将自动重定向到存储在数据库中的某些其他URL。
As far i understand your question, first you need .htaccess for SEO friendly URL. 据我所知,您首先需要.htaccess以获得SEO友好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. 现在,例如
www.example.com/jobs.php?id=123456
是一个URL,您想将用户重定向到存储在数据库中的www.example.com/this-is-my-first-job
。 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? 如何从子弹中获取ID?
write in .htaccess 用.htaccess写
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*)$ index.php?slug=$1 [QSA,NC,L]
now in PHP 现在在PHP
if(isset($_GET['slug'])){
//get the id from database against slug
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.