问题描述
注意:我已经尝试了 这个问题 但它们要么不起作用,要么给我一个无限重定向循环错误.
Note: I have tried the suggestions under this question but they either don't work or give me an infinite redirect loop error.
我的 .htaccess 文件中有以下内容:
I have the following in my .htaccess file:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
# Rewrite old links to new
Redirect 301 /howitworks.php /how-it-works
Redirect 301 /testimonials.php /testimonials
Redirect 301 /contact_us.php /customer-service
Redirect 301 /affiliates.php /affiliates
Redirect 301 /account.php /customer/account
Redirect 301 /shopping_cart.php /checkout/cart
Redirect 301 /products.php /starter-kits
Redirect 301 /login.php /customer/account/login
# Force to Admin if trying to access admin
RewriteCond %{HTTP_HOST} www\.example\.com [NC]
RewriteCond %{REQUEST_URI} admin [NC]
RewriteRule ^(.*)$ https://admin.example.com/index.php/admin [R=301,L,QSA]
# Compress, Combine and Cache Javascript/CSS
RewriteRule ^(index.php/)?minify/([^/]+)(/.*.(js|css))$ lib/minify/m.php?f=$3&d=$2
# Always send 404 on missing files in these folders
RewriteCond %{REQUEST_URI} !^/(media|skin|js)/
# Never rewrite for existing files, directories and links
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_URI} !server-status
# Rewrite everything else to index.php
RewriteRule .* index.php [L]
# Force www in url and non-example domains to example
RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
RewriteCond %{HTTP_HOST} !^ww2\.example\.com [NC]
RewriteCond %{HTTP_HOST} !^qa\.example\.com [NC]
RewriteCond %{HTTP_HOST} !^uat\.example\.com [NC]
RewriteCond %{HTTP_HOST} !^local\.example\.com [NC]
RewriteCond %{HTTP_HOST} !^admin\.example\.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L,QSA]
</IfModule>
我需要一个重写来执行以下操作:
I need a rewrite that will do the following:
重写:http://subdomain.example.com/ to http://subdomain.example.com/page
我还想隐藏/page(/会像/page 一样),但这不是必需的要求.另外,我希望它可以使用 HTTP 或 HTTPS.
I would also like this to hide the /page (/ would act as if it was /page) but this is not a necessary requirement. Also, I'd like it to work with HTTP or HTTPS.
非常感谢任何帮助,因为我已经为此苦苦挣扎了几个小时.
Any help is greatly appreciated because I have been struggling with this for hours.
推荐答案
根路径的正确重定向很简单:
A correct redirect of the root path is simply :
RewriteEngine On
RewriteRule ^/$ /page [R]
仅在一个子域上强制执行此操作(如果您的重写块位于虚拟主机定义中,则几乎不会发生这种情况):
to force this only on one subdomain (which should barely happen if your rewrite block is in a virtualhost definition) :
RewriteEngine on
RewriteCond %{HTTP_HOST} =subdomain.example.com
RewriteRule ^/$ /page [R]
这篇关于使用 Mod_Rewrite 将 ROOT 重写为另一个路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!