[英]URL Rewrite based on trailing slashes in requested url
I'm working on a dynamic php website which serves content from database. 我正在一个动态的php网站上,该网站提供数据库中的内容。 Currently I'm having four PHP files-
index.php
, a.php
, b.PHP
, c.php
. 目前我有四个PHP文件-
index.php
, a.php
, b.PHP
, c.php
。 These serves result from the database as par the requested URL. 这些将来自数据库的结果用作请求的URL。 eg.
例如。
If the requested url example.com
then index.php
serves results. 如果请求的网址为
example.com
则index.php
提供结果。
If the requested url is example.com/xyz.html
then a.php
first exact xyz
from the url and then serves result for xyz
. 如果所请求的网址是
example.com/xyz.html
则a.php
首先从该网址中准确输入xyz
,然后将结果提供给xyz
。 [rewrite example.com/a.php
to example.com/xyz.html
] [将
example.com/a.php
重写为example.com/xyz.html
]
If the requested url is example.com/x/y.html
then b.php
first extract x
and y
from the requested url and then serves result for y
page [rewrite example.com/a.php/b.php
to example.com/x/y.html
]. 如果请求的URL是
example.com/x/y.html
则b.php
首先从请求的URL中提取x
和y
,然后将结果提供给y
页面[将example.com/a.php/b.php
重写为example.com/x/y.html
]。
If the requested url is example.com/x/y/z.html
the c.php
first extract x
, y
, z
from the url and then serve result for z
page (rewrite example.com/a.php/b.php/c.php
to example.com/x/y/z.html
). 如果要求的网址是
example.com/x/y/z.html
则c.php
首先从网址中提取x
, y
, z
,然后将结果提供给z
页面(重写example.com/a.php/b.php/c.php
到example.com/x/y/z.html
)。
In short if the requested url is - 简而言之,如果请求的网址是-
example.com
or example.com/
- then results will be served by index.php
example.com
或example.com/
结果将由index.php
example.com/anything.html
- then result will be served by a.php
example.com/anything.html
然后结果将由a.php
example.com/anything/anything.html
- then result will be served by b.php
example.com/anything/anything.html
然后结果将由b.php
example.com/anything/anything/anything.html
- then result will be parsed by c.php
example.com/anything/anything/anything.html
然后结果将由c.php
解析
So how can i achieve such functionality using URL rewritting ? 那么如何使用URL重写实现此类功能? Please reply with
.htaccess
code for such functionality. 请使用
.htaccess
代码答复此功能。
Put this code in your DOCUMENT_ROOT/.htaccess
file: 将此代码放在您的
DOCUMENT_ROOT/.htaccess
文件中:
DirectoryIndex index.php
RewriteEngine On
RewriteRule ^(?!(a|b|c)\.php$)[^/.]+\.php$ /a.php [L,NC]
RewriteRule ^[^/]+/[^/.]+\.php$ /b.php [L,NC]
RewriteRule ^[^/]+/[^/]+/[^/.]+\.php$ /c.php [L,NC]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.