【问题标题】:apache 2.4 AliasMatch possible to pass get parameters?apache 2.4 AliasMatch 可以传递获取参数吗?
【发布时间】:2018-08-30 20:40:25
【问题描述】:

是否可以在 Linux 上的 Apache 2.4 中使用 AlisaMatch 传递附加的 get 参数?

我想对DocumentRoot 之外的文件夹进行重定向,因此RewriteRule.htaccess 中不起作用。尝试AliasMatch 似乎重定向正在寻找一个名为/home/other/index.php?a=$1&b=$2 的文件而不是/home/other/index.php 加上附加的get 参数?a=$1&b=$2

AliasMatch "^/myfolder/(.*)/(.*)$" "/home/other/index.php?a=$1&b=$2"

更新 在具有完整目录路径的 htaccess 中使用 RewriteRule 确实可以按预期工作。

【问题讨论】:

  • 问题,为什么不在虚拟主机上下文中使用 mod_rewrite,就像在 .htaccess 中也无效的 AliasMatch 一样?请记住 .htaccess 不是用于重写的仓库,它只是让非管理员在特定目录中配置指令!

标签: apache .htaccess httpd.conf


【解决方案1】:

您不应该在此处使用 AliasMatch,只需在 Apache 配置或虚拟主机配置中将 Alias 与这些指令一起使用:

Alias "/myfolder" "/home/other"

<Directory /home/other>
   Options Indexes FollowSymLinks ExecCGI
   AllowOverride All
   Order allow,deny
   Allow from all
   Require all granted

   RewriteEngine On

   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteRule ^([\w-]+)/([\w-]+)/?$ index.php?a=$1&b=$2 [L,QSA]

</Directory>

PS:如果你愿意,你也可以在/home/other/.htaccess里面使用这个规则:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\w-]+)/([\w-]+)/?$ index.php?a=$1&b=$2 [L,QSA]

【讨论】:

  • 这似乎无法在 .conf 中正常工作。我仍然只能使用完整路径而不是相对路径在.htaccess 中获得重定向。
  • 在发布之前,我已经从我的 vhost.conf 和 .htaccess 文件中验证了这些规则工作正常。
猜你喜欢
  • 2015-12-16
  • 1970-01-01
  • 2023-04-08
  • 2016-12-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-02-11
相关资源
最近更新 更多