htaccess 在 php 中重写 URL
请帮忙在php中通过htaccess将动态url转换为静态url。
示例 1:
www.example.com/say.php?name=ksrtc-palakkad-kerala&id=c669239
(动态 URL)
www.example.com/say/ksrtc-palakkad- kerala-c669239.html
(静态 URL)
示例 2:
www.example.com/index.php?name=ksrtc-palakkad-kerala&id=c669239
(动态网址)
www.example.com/say/ksrtc-palakkad-kerala-c669239 .html
(静态 URL)
问候, 普拉巴特
Please help to convert dynamic url to static url by htaccess in php.
Example 1:
www.example.com/say.php?name=ksrtc-palakkad-kerala&id=c669239
(Dynamic URL)
www.example.com/say/ksrtc-palakkad-kerala-c669239.html
(Static URL)
Example 2:
www.example.com/index.php?name=ksrtc-palakkad-kerala&id=c669239
(Dynamic URL)
www.example.com/say/ksrtc-palakkad-kerala-c669239.html
(Static URL)
Regards,
Prabhat
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该创建一个如下所示的 .htaccess:
现在完整路径将被重定向到 index.php - 这将是您的单个入口点,您可以通过
$_SERVER['REQUEST_URI']
如果我没记错的话。现在,您的工作是编写一组规则来了解此 url 匹配的所有可能的路由(正则表达式),然后解析 url 并相应地设置 GET 变量(来自第二个示例 - name、id)。如果该 url 与任何已知 url 都不匹配 - 将其转发到您的错误页面。
而且你还应该进行反向路由,如果有人打开一个带有简单获取变量的网址,例如“index.php?name=ksrtc-palakkad-kerala&id=c669239”,你应该使用 301 永久重定向重定向到“SEO”网址“ /say/ksrtc-palakkad-kerala-c669239.html"
如果这不能回答您的问题,请详细说明。
You should create an .htaccess that looks something like this:
Now the full path would be redirected to index.php - this will be your single entry point, you could access it through
$_SERVER['REQUEST_URI']
if I recall well.Now it will be your job to write set of rules to know all the possible routes that this url matches (regular expressions), then parse the url and set the GET variables accordingly (from your second example - name, id). If the url doesn't match any of the known urls - forward it to your error page.
And also you should do reverse-routing, if someone opens an url with plain get variables like "index.php?name=ksrtc-palakkad-kerala&id=c669239" you should redirect with 301 PERMANENT REDIRECT to the "SEO" url "/say/ksrtc-palakkad-kerala-c669239.html"
If this doesn't answer your question, please elaborate.