How to define friendly URL rules using .htaccess?

2019-09-20 11:31发布

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/ ...

I wrote this rule after spending time on google:

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

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.

3条回答
再贱就再见
2楼-- · 2019-09-20 12:12

Here is a very simple tutorial on using Apache's mod_rewrite to create friendly URLs.

查看更多
Lonely孤独者°
3楼-- · 2019-09-20 12:13

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

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

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

查看更多
闹够了就滚
4楼-- · 2019-09-20 12:25

Probably a bit too much to take just right now but you could look at some of the available MVC frameworks to help you solve this. I'm guessing that the host only offers PHP 5.2 so I'd take a look at the routing/controller solution from Zend Framework 1.12 to solve this as that can be implemented into existing code without too much trouble.

查看更多
登录 后发表回答