如何使用.htaccess定义友好的URL规则?

编程入门 行业动态 更新时间:2024-10-28 14:23:17
本文介绍了如何使用.htaccess定义友好的URL规则?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

很长时间以来我都在尝试定义重写规则,但是我还不能成功?我有一个简单的页面 www.myURL/pdf.php?id= 2 .我想通过以下方式使其友好: www.myURL/pdf/2/ ...

Long time I am trying to define Rewriting rules but I could not succeed yet? I have a simple page www.myURL/pdf.php?id=2. I want to make it friendly by this: www.myURL/pdf/2/ ...

我在Google上度过了一段时间后写下了以下规则:

I wrote this rule after spending time on google:

Options +FollowSymlinks RewriteEngine On RewriteRule ^pdf/([0-9]+)\$ pdf.php?id=$1.

当我在服务器上上传.htaccess文件并尝试先运行时,它给我500错误.第二次加载页面,但无法显示友好的URL;它像以前一样显示. 请告诉我更好的解决方案,我遵循了许多说明使其变得有用,但未能成功.除非我向他显示友好的URL,否则我的客户不会走的更远.请尽快帮助我.这是我的客户端托管组织:Justhost.

When I uploaded my .htaccess file on server and try to run first it give me 500 ERROR. Second time it loaded page but it could not show me friendly URL; it was showing as before. Kindly tell me better solution, I followed many instructions to make it useful but could not successful. My Client are not going further unless I showed him friendly URL. kindly help me as soon as possible. This is my client hosting Organization: Justhost.

推荐答案

您可以使用Apache的重写引擎来做到这一点.像这样:

You can do this using Apache's Rewrite Engine. Something like this:

RewriteEngine On RewriteRule ^pdf/([0-9/]+)$ /pdf.php?id=$1 [L]

这将使您可以转到 yoursite/pdf/192 而不是 yoursite/pdf.php?id=192

This will allow you to go to yoursite/pdf/192 instead of yoursite/pdf.php?id=192

更多推荐

如何使用.htaccess定义友好的URL规则?

本文发布于:2023-11-02 03:20:39,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1551229.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用   友好   定义   规则   htaccess

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!