-3

我是这个路由和 mod-reqrite 等的完整初学者。东西。我在这里遵循了有关 URL 路由的教程:http://wettone.com/code/clean-urls,但无法使其正常工作。

我只想路由 ALL 和任何类型的 URL,例如

http://wettone.com/weblog/2000/01/01/example
http://wettone.com/weblog/2000/01/01
http://wettone.com/weblog/2000/01
http://wettone.com/weblog/2000

到文档根目录中的 weblog 文件夹中的 index.php 脚本,目录路径为:

http://wettone.com/weblog/index.php?y=2000&m=01&d=01&n=example
http://wettone.com/weblog/index.php?y=2000&m=01&d=01
http://wettone.com/weblog/index.php?y=2000&m=01
http://wettone.com/weblog/index.php?y=2000

我怎样才能做到这一点。顺便说一句,我更喜欢保持简单而不使用任何框架

提前谢谢...

编辑:我可以知道为什么投反对票吗?我做错了什么?我不能在这里问这种类型的问题吗?

4

2 回答 2

1

所以基本上你希望一切都映射到 index.php?如果是,这里的片段取自 symfony1 htaccess

# we check if the .html version is here (caching)
RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f

# no, so we redirect to our front web controller
RewriteRule ^(.*)$ index.php [QSA,L]

在 php 中,如果我没记错的话,你必须使用 $_SERVER['REQUEST_URI'] 来解析 uri 并决定显示什么

最好只使用 symfony2 组件来完成这项工作http://symfony.com/doc/current/components/routing/introduction.html :)

于 2013-01-31T13:04:29.480 回答
0

使用 htaccess

Options +FollowSymLinks
RewriteEngine On
RewriteBase /weblog/


RewriteRule (.*)/(.*)/(.*)/(.*)$ index.php?y=$1&m=$2&d=$3&n=$4
于 2013-01-31T13:00:47.600 回答