【问题标题】:.htaccess rewrite rule with DocumentRoot subdomain.htaccess 使用 DocumentRoot 子域重写规则
【发布时间】:2014-03-06 08:39:52
【问题描述】:

我正在尝试实现一些 htaccess 重写规则。但是在htaccess中不是专业人士。

我有一个子域网关(如:.htaccess and rewrite sub domains 中所述)

现在我想使用 SEO 友好的 URL。在这种情况下,网关有一些子文件夹,即电子邮件。

http://gateway.example.com/email/Param1/Param2/

此网址应改写为http://gateway.example.com/email/index.php?hash=Param1&hash2=Param2

在电子邮件文件夹中,我创建了一个包含以下内容的 .htaccess 文件:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.* - [L]
RewriteRule ^/(.*)/(.*)/ index.php?hash=$1&hash2=$2

当我请求http://gateway.example.com/email/Param1/Param2/ 时,我现在得到一个 404。规则有什么问题?

【问题讨论】:

  • 好的,那么转到gateway.example.com 是否按预期工作?你的文档根是什么?
  • @PanamaJack 是的,它确实有效。

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


【解决方案1】:

你应该这样做

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/?([^/]*)/([^/]*)/ /email/index.php?hash=$1&hash2=$2 [L]

【讨论】:

    【解决方案2】:

    你可以试试这个。

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^/([^/]*)/([^/]*)/ index.php?hash=$1&hash2=$2
    

    *您需要通过将 AllowOverride 从 non 更改为 all 来配置 apache(httpd) 以接受 UrlRewrite:

    <Directory "/var/www/html">
     Options Indexes FollowSymLinks
     AllowOverride all
     Order allow,deny
     Allow from all
    </Directory>
    

    【讨论】:

    • 你是否允许 .htaccess 在你的 apache 服务器上?
    • *你需要通过将 AllowOverride 从 non 更改为 all 来配置 apache(httpd) 以接受 UrlRewrite(在 centos 的 /etc/httpd/config/httpd.conf 上): 选项索引 FollowSymLinks AllowOverride all Order allow,deny Allow from all
    猜你喜欢
    • 2012-06-11
    • 2010-09-26
    • 2011-11-21
    • 2012-07-31
    • 1970-01-01
    • 2018-10-16
    • 2013-05-23
    • 2012-08-12
    • 1970-01-01
    相关资源
    最近更新 更多