apache - 使用 Mod_Rewrite 将 ROOT 重写为另一个路径

标签 apache .htaccess mod-rewrite url-rewriting

注:我已经尝试了 this question 下的建议但它们要么不起作用,要么给我一个无限重定向循环错误。

我的 .htaccess 文件中有以下内容:

<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>

我需要一个重写来执行以下操作:

改写:http://subdomain.example.com/ http://subdomain.example.com/page

我也想隐藏/page (/会像/page 一样),但这不是必要的要求。另外,我希望它与 HTTP 或 HTTPS 一起使用。

非常感谢任何帮助,因为我已经为此苦苦挣扎了几个小时。

最佳答案

根路径的正确重定向很简单:

RewriteEngine On
RewriteRule ^/$ /page [R]

仅在一个子域上强制执行此操作(如果您的重写块在虚拟主机定义中,则几乎不会发生这种情况):
RewriteEngine on
RewriteCond %{HTTP_HOST} =subdomain.example.com
RewriteRule ^/$ /page [R]

关于apache - 使用 Mod_Rewrite 将 ROOT 重写为另一个路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2766443/

相关文章:

linux - mod_perl 看不到/tmp 中的文件

regex - .htaccess SetEnvIfNoCase 主机排除特定子域

apache - 目录中多个文件重命名,需要htaccess规则重定向

.htaccess - symfony2重写规则.htaccess app.php

apache - htaccess将index.php重定向到根目录(包括子域)

django - 如何在同一域上部署WordPress网站和Django网站?

apache - Apache HTTP 服务器上的 SSL

css - 启用 SSL 后,如果调用网站的 http 版本,图标字体无法正确显示

php - Symfony - app_dev.php 中的 ClassNotFoundException

php - 使用 iframe 在 SSL 站点上显示具有绝对 URL 的非 SSL 内容