htaccess从外部删除url文件夹并在内部重定向

时间:2014-05-20 05:58:54

标签: .htaccess

我管理员要从网址中删除该文件夹,但我无法重定向回来。请帮忙!

# externally redirect /dir/foo to /foo
RewriteCond %{THE_REQUEST} pages/
RewriteRule pages/(.*)$ $1 [L,NC,R]

# internally forward /foo to /dir/foo
#what goes here?

编辑: 另外,我怎么能把它放在相同的代码上呢?

#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule ^(.*)$ profile.php?username=$1 [L]

我希望用户名与localhost / test / user1相似,而不是localhost / test / profile.php?username = user1

1 个答案:

答案 0 :(得分:0)

内部重定向意味着URL重写(如果我没有被误解)

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/dir/
RewriteRule ^(.*)$ /dir/$1 [L]

注意:为了防止外部重定向,我没有使用[R]标志。

修改

我可以在子目录localhost/test看到你的情况所以,你必须设置RewriteBase如下:

RewriteEngine On
RewriteBase /test
RewriteCond %{REQUEST_URI} !^/dir/
RewriteRule ^(.*)$ /test/dir/$1 [L]

编辑包含的用户个人资料重写规则

RewriteEngine On
RewriteBase /test
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /test/profile.php?username=$1 [L]

RewriteCond %{REQUEST_URI} !^/dir/
RewriteRule ^(.*)$ /test/dir/$1 [L]