首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Mod_Rewrite将根重写到另一条路径

使用Mod_Rewrite将根重写到另一条路径
EN

Stack Overflow用户
提问于 2010-05-04 15:01:27
回答 3查看 47.8K关注 0票数 18

注意:,我在this question下尝试过这些建议,但是它们要么不起作用,要么给我一个无限的重定向循环错误。

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

代码语言:javascript
复制
<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/ to http://subdomain.example.com/page

我也希望这样隐藏/page (/将表现为它是/page),但这不是必要的要求。另外,我希望它能与HTTP或HTTPS一起工作。

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

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2011-07-11 05:18:26

根路径的正确重定向只需:

代码语言:javascript
复制
RewriteEngine On
RewriteRule ^/$ /page [R]

要强制在一个子域上执行此操作(如果重写块位于虚拟主机定义中,则几乎不会发生这种情况):

代码语言:javascript
复制
RewriteEngine on
RewriteCond %{HTTP_HOST} =subdomain.example.com
RewriteRule ^/$ /page [R]
票数 25
EN

Stack Overflow用户

发布于 2012-12-30 21:09:31

复制已删除的回复:

在您的文档根的htaccess中,只需:

代码语言:javascript
复制
RewriteEngine on
RewriteCond %{HTTP_HOST} =subdomain.example.com
RewriteRule ^$ /page
票数 7
EN

Stack Overflow用户

发布于 2016-11-07 16:56:03

您有两个选项可以将根重写到另一条路径,

  1. DirectoryIndex:

DirectoryIndex anotherPath

  • Mod-rewrite:

RewriteEngine on RewriteRule ^/?$ /anotherPath L

您可以使用上述选项之一将example.com/内部重定向到example.com/anotherPath

参考文献:

  1. https://httpd.apache.org/docs/current/mod/mod_dir.html
  2. http://httpd.apache.org/docs/current/mod/mod_rewrite.html
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2766443

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档