htaccess:友好的网址 - 尾随斜线和“伪子目录”

时间:2016-08-23 20:55:49

标签: php apache .htaccess mod-rewrite

我想用htaccess(if (isAdded) { //Do your UI stuff here } 重写mod)制作假子目录,但它并没有真正起作用......

我有这个网址:

fakefolder/forget-password

parent-directory/index.php?version=1&do=forget-password&email=example@domain.com&token=85085ab92fcfd5dada280c73f7f494ec注意:'email'变量正在使用mysql验证,我使用*以防值为电子邮件,因此它也可以是用户名(filter_var) 。 email=username是一个真实的目录。 parent-directory是动态的,可以是2或3或字符串,并显示不同的结果,因此在这种情况下,versionversion=1fakefolder以及任何其他值(version=2

以及此fakefolder2代码:

htaccess

如果我尝试制作类似这样的内容:Options +FollowSymLinks -MultiViews RewriteEngine On # Set configuration file php_value auto_prepend_file configuration.inc.php # Start Rewriting RewriteBase /parent-directory/ RewriteCond %{SCRIPT_FILENAME} !-d RewriteCond %{SCRIPT_FILENAME} !-f RewriteRule ^fakefolder$ index.php?version=1 [QSA,L] 它无效,或显示404

有可能吗? (如果是,那么它可以是多层次的吗?例如RewriteRule ^([a-z])$/forget-password$ index.php?version=$1&do=forget-password [QSA,L]而不是index.php?version=1&do=forget-password&email=example@domain.com -> ([a-z])$/forget-password/username)?

请原谅我的英文,非常感谢。

1 个答案:

答案 0 :(得分:0)

请尝试以下规则:

# Set configuration file
php_value auto_prepend_file configuration.inc.php

Options +FollowSymLinks -MultiViews
RewriteEngine On
# Start Rewriting
RewriteBase /parent-directory/

RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]

RewriteRule ^([\w-]+)/forget-password/([\w-]+)/?$ index.php?version=$1&do=forget-password&email=$1 [QSA,L,NC]

RewriteRule ^([\w-]+)/forget-password/?$ index.php?version=$1&do=forget-password [QSA,L,NC]

RewriteRule ^fakefolder/?$ index.php?version=1 [QSA,L,NC]