Apache Htaccess域重定向,如何持久化当前页面?
我有许多域,主域是Apache Htaccess域重定向,如何持久化当前页面?,apache,.htaccess,laravel,mod-rewrite,redirect,Apache,.htaccess,Laravel,Mod Rewrite,Redirect,我有许多域,主域是example.com,附加域是example1.com,example2.com,example3.com 我希望这些域都重定向到主域,example.com 我可以使用以下代码执行此操作: RewriteCond %{HTTP_HOST} ^example1.com$ [OR] RewriteCond %{HTTP_HOST} ^www.example1.com$ RewriteRule ^/?$ "http://example.com" [R=301,L] 这会将exa
example.com
,附加域是example1.com
,example2.com
,example3.com
我希望这些域都重定向到主域,example.com
我可以使用以下代码执行此操作:
RewriteCond %{HTTP_HOST} ^example1.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.example1.com$
RewriteRule ^/?$ "http://example.com" [R=301,L]
这会将example1.com
重定向到example.com
,很简单。但是,如果我键入
example1.com/products
,则URL不会更改,不会发生重定向
如何使这些附加域重定向到主域并保持用户的当前位置(web目录)?清除浏览器缓存并尝试:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?example1\.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [NC,L,R]
清除浏览器缓存,然后尝试:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?example1\.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [NC,L,R]
这似乎仍然具有相同的行为,它只执行重定向,它将
index.php
添加到末尾,不返回特定页面,返回主页。因此,最终结果看起来像example.com/index.php
,而不管用户当前在哪个页面上。Remome^和$from条件:RewriteCond%{HTTP_HOST}example1.com[或]完全相同的行为@vasilyths这似乎仍然具有相同的行为,它只会在末尾添加index.php
,然后进行重定向,不返回特定页面,返回主页。因此,不管用户当前在哪个页面上,最终结果看起来都像example.com/index.php
。Remome^和$from条件:RewriteCond%{HTTP_HOST}example1.com[或]与上述答案完全相同的行为@VasilySame行为,重定向到主页并附加index.php
,认为这部分可能是特定于Laravel的,因为进一步的重写由routes文件处理。与上面的回答相同,重定向到主页并附加index.php
,认为这部分可能是特定于Laravel的,因为进一步的重写由routes文件处理。