所以你只想重定向/apps/dept/
, 正确的?这应该有效。将其放置为.htaccess
或者在 Apache 配置中example.orgname.state.tx.us
一切都应该按预期工作。
RewriteEngine on
RewriteRule ^/apps/dept/(.*)$ http://example.orgname.texas.gov/apps/dept/$1 [NC,L,R=301]
现在,任何发送到此 URL 的请求
http://example.orgname.state.tx.us/apps/dept/
现在将转到此 URL:
http://example.orgname.texas.gov/apps/dept/
URL 右侧的所有请求参数也将一起传递。
EDIT只需重读您在这里写的内容即可:
我将 .htaccess 文件放在 /var/www/example/html/apps/dept 目录中
如下。
The .htaccess
我上面描述的应该放在/var/www/example/html/
并且不在/apps/dept
子目录。
但如果你想要同样的行为.htaccess
放在/apps/dept
然后使用这个:
RewriteEngine on
RewriteRule ^(.*)$ http://example.orgname.texas.gov/apps/dept/$1 [NC,L,R=301]
这样,任何来自的请求/apps/dept
愿意去example.orgname.texas.gov/apps/dept/
包括子目录/apps/dept
例如/apps/dept/test_app1
, /apps/dept/test_app2
or /apps/dept/test_app3
.
或者也许尝试这个:
RewriteEngine on
RewriteRule (.*)$ http://example.orgname.texas.gov/apps/dept/$1 [NC,L,R=301]
注意我删除了^
这将迫使RewriteRule
以匹配 URL 的开头。