【问题标题】:Redirect URL alternatives with htaccess使用 htaccess 重定向 URL 替代方案
【发布时间】:2012-09-10 21:19:14
【问题描述】:

我可以使用以下指令将 URL 重定向到带有 htaccess 的另一个 URL:

RewriteCond %{REQUEST_URI} ^/example$
RewriteRule (.*) /pages/example [L,R=301]

RewriteCond %{REQUEST_URI} ^/example
RewriteRule (.*) /pages/example [L,R=301]

但我想在 htaccess 中使用单个指令来实现这一点,并且该指令应涵盖所有替代方案;

http://mydomain.com/example -> http://mydomain.com/pages/example
http://mydomain.com/example/ -> http://mydomain.com/pages/example
http://mydomain.com/example/test -> http://mydomain.com/pages/example/test

如何使用单个 .htaccess 执行此操作?有什么想法吗?

感谢您的帮助。

【问题讨论】:

    标签: .htaccess


    【解决方案1】:

    试试这个:

    RewriteRule ^example(/(test)?)?$ /pages/example$1 [L,R=301]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-12-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-23
      相关资源
      最近更新 更多