如何为获取值重写url?

时间:2016-12-17 15:51:30

标签: php .htaccess url-rewriting

我是PHP的初学者。我的这段代码工作正常,可以从url中删除.php。像:

   http://localhost/travel/route?source=London&destination=paris&route=

但我想要这样的网址:

 http://localhost/travel/route/source/London/destination/paris

这是我的代码

RewriteEngine On
RewriteRule ^([^\.]+)$ $1.php
RewriteRule ^([^\.]+)$ $1.php

RewriteRule ^route/([0-9]+)/([a-zA-Z0-9_-]+)$ /route?source=$1&destination=$2 [L,QSA]

1 个答案:

答案 0 :(得分:1)

这是我使用的一个例子。希望它可以帮助你:))

DirectoryIndex index.php

RewriteEngine On

RewriteRule ^([a-z0-9_-]+)/([a-z0-9_-]+)/([a-z0-9_-]+)/?$ index.php?page=$1&action=$2&id=$3 [L,NC]
RewriteRule ^([a-z0-9_-]+)/([a-z0-9_-]+)/?$ index.php?page=$1&action=$2 [L,NC]
RewriteRule ^([a-z0-9_-]+)/?$ index.php?page=$1 [L,NC]
RewriteRule ^dashboard/?$ index.php [L,NC]