问题描述
我想找到一个更好的解决方案来解决这个问题。我没有使用像硅石任何框架,Yii的等等。因此我没有被这些框架提供的通用路由处理机制。我的URL模式像
I am trying to find a better solution to solve the issue. I am not using any framework like silex, Yii etc. Thus i do not have the general routing handling mechanism provided by these frameworks. My url patterns are like
routing.php
routing.php?action=create
routing.php?action=list&id=1
和产生的URL我想有是
and the resulting url i want to have are
/routing
/routing/create
/routing/list/1
我的.htaccess一些非常基本的了解,下面是我目前书院
i have some very basic understanding of .htaccess, below is my current foundings
RewriteEngine On
RewriteBase /name/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
这些codeS很好地把所有的.php到/某事。但是我是一个stucked继续生成获取/ 路由/创建
和 /路由/列表/ 1
。鸭preciate任何帮助。
These codes work well to put any .php to /something. However i am a stucked to continue to generate a general solution for getting /routing/create
and /routing/list/1
. Appreciate for any helps.
推荐答案
有你的.htaccess这样的:
Have your .htaccess like this:
RewriteEngine On
RewriteBase /name/
RewriteCond %{DOCUMENT_ROOT}/name/$1.php -f
RewriteRule ^([^/]+)/([^/]+)/?$ $.php1?action=$2 [L,NC,QSA]
RewriteCond %{DOCUMENT_ROOT}/name/$1.php -f
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/?$ $1.php?action=$2&id=$3 [L,NC,QSA]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [L]
这篇关于路由使用的.htaccess的php查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!