apache url为随机数重写

时间:2013-12-01 21:27:57

标签: php regex apache .htaccess mod-rewrite

问题是我基于GET方法捕获我的网址...所以我的网址看起来像

localhost/test/index.php?vic=24

其中vic是可变的......

我的网站上还有一个按钮,每次随机化我的vic。

<a href="'.htmlentities($_SERVER['PHP_SELF']).'?vic='.randomVic($link).'">

请注意,randomVic($ link)是一个每次都返回随机数的函数。

我想要实现的是我的网址看起来像

localhost/test/index.php?vic=24 -> localhost/test/24
每个随机数

等等。 我真的需要帮助,我尝试了很多.htacces mods进行重写(条带化.php,删除索引,......)但是没有一个能够工作,因为我需要它们。

谢谢!

2 个答案:

答案 0 :(得分:0)

RewriteRule ^test/([0-9]+)$ index.php?vic=$1

根据以下评论进行编辑

答案 1 :(得分:0)

启用mod_rewrite.htaccesshttpd.conf(如果尚未启用),然后将此代码放入 DOCUMENT_ROOT/vic.htaccess文件

RewriteEngine On
RewriteBase /vic/

RewriteCond %{THE_REQUEST} \s/+vic/index\.php\?vic=([^\s&]+) [NC]
RewriteRule ^ %1? [R=302,L]

RewriteRule ^([0-9]+)/?$ index.php?vic=$1 [L,QSA,NC]