使用mod_rewrite重写ROOT到另一条路径 [英] Use Mod_Rewrite to Rewrite ROOT to Another Path

查看:307
本文介绍了使用mod_rewrite重写ROOT到另一条路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

注意:我曾尝试在<一的建议href="http://stackoverflow.com/questions/990392/htaccess-rewrite-to-redirect-root-url-to-subdirectory">this问题但他们要么没有工作或给我无限重定向循环错误。

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/ http://subdomain.example.com/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.

任何帮助是极大的AP preciated,因为我一直在努力奋斗着这个好几个小时。

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到另一条路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆