如何使用.htaccess定义友好的URL规则? [英] How to define friendly URL rules using .htaccess?
问题描述
很长时间以来我都在尝试定义重写规则,但是我还不能成功?我有一个简单的页面 http://www.myURL.com/pdf.php?id= 2 .我想通过以下方式使其友好: http://www.myURL.com/pdf/2/ ...
Long time I am trying to define Rewriting rules but I could not succeed yet? I have a simple page http://www.myURL.com/pdf.php?id=2. I want to make it friendly by this: http://www.myURL.com/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.com.
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.com.
推荐答案
您可以使用Apache的重写引擎来做到这一点.像这样:
You can do this using Apache's Rewrite Engine. Something like this:
RewriteEngine On
RewriteRule ^pdf/([0-9/]+)$ /pdf.php?id=$1 [L]
这将使您可以转到 http://yoursite.com/pdf/192 而不是 http://yoursite.com/pdf.php?id=192
This will allow you to go to http://yoursite.com/pdf/192 instead of http://yoursite.com/pdf.php?id=192
这篇关于如何使用.htaccess定义友好的URL规则?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!