繁体   English   中英

mod_rewrite-根据URL路径的规则

[英]mod_rewrite - rule according to url path

我在regex方面非常虚弱,我需要有关执行以下操作的mod_rewrite规则的帮助:

  1. 如果URL仅仅是域名:xyz.com - >去上目录的index.php像这样xyz.com/a/index.php
  2. 如果URL包含路径: xyz.com/abcde- >转到目录b上的index.php并将路径更改为如下所示的参数: xyz.com/b/index.php?id=abcde

目录a和b当然都在同一根目录下。

我设法做到了2,但我不知道如何包括规则1。

您可以使用以下内容:

RewriteEngine on
#--if url is just the domain name--#
#--rewrite to /a/index.php--#
RewriteRule ^$ /a/index.php [NC,L]

#--if it contains path--#
#--rewrite to /b/index.php?id=path
RewriteRule ^((?!b).+)$ /b/index.php?id=$1 [NC,L]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM