【问题标题】:HTACCESS - Applying some simple mod_rewrite rulesHTACCESS - 应用一些简单的 mod_rewrite 规则
【发布时间】:2012-11-14 05:09:43
【问题描述】:

这很紧急。我需要一些 htaccess 规则的帮助。线索是当用户收到某事的答案时,真正的 url 将是 www.mydomain.com/results.html/sth 但他必须只能在他的浏览器中看到 www.mydomain.com/sth 并且当我将他重定向到家时页面 (www.mydomain.com/index.html) 的 url 只能是 www.mydomain.com。

谢谢

【问题讨论】:

  • 你有没有尝试我下面的建议?

标签: apache .htaccess mod-rewrite url-rewriting


【解决方案1】:
#this is for the www.yourdomain.com/index.html
RewriteRule ^$  index.html  [L]
RewriteRule ^/$  index.html [L]

#this is for the results
RewriteRule ^([^/]+)$  results.html?$1
RewriteRule ^([^/]+)/$ results.html?$1

【讨论】:

  • 谢谢。这适用于 results.html,但不幸的是不适用于主页 index.html。链接到 www.mydomain.com/index.html 或 www.mydomain.com/ 将我带到 www.mydomain.com/index.html 或 www.mydomain.com/ 但显示 www.mydomain.com/results.html 的内容.
【解决方案2】:

将前 3 行代码替换为:

DirectoryIndex index.html

默认情况下它应该可以工作

【讨论】:

  • 仍然与我之前描述的完全不同。链接到 www.mydomain.com/ 将我带到那里,但不幸的是内容来自 www.mydomain.com/results.html。
【解决方案3】:

这应该可行:

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/(results|index)\.html
RewriteCond %{REQUEST_URI} !^/?$
RewriteRule ^(.*)$ /results.html/$1

RewriteRule ^index\.html$ / [R=301,L]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-31
    相关资源
    最近更新 更多