Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.htaccess htaccess从url外部删除文件夹并在内部重定向_.htaccess - Fatal编程技术网

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

.htaccess htaccess从url外部删除文件夹并在内部重定向,.htaccess,.htaccess,我试图从url中删除该文件夹,但无法重定向回该文件夹。请帮忙 # 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_FILENAM

我试图从url中删除该文件夹,但无法重定向回该文件夹。请帮忙

# 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内部重定向意味着URL重写(如果我没有被误解的话)

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

编辑

我可以看到您在子目录
/test
中的
localhost
上进行了hostead,因此,您必须设置
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]

这摧毁了我的整个网站。。我希望localhost/test/pages/info转到localhost/test/info这似乎不起作用。它也会压碎一切
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]