简体   繁体   English

mod_rewrite-根据URL路径的规则

[英]mod_rewrite - rule according to url path

I am pretty weak at regex, and I need help with a mod_rewrite rule that does the following: 我在regex方面非常虚弱,我需要有关执行以下操作的mod_rewrite规则的帮助:

  1. If the url is just the domain name: xyz.com -> go to index.php on directory a like so xyz.com/a/index.php 如果URL仅仅是域名:xyz.com - >去上目录的index.php像这样xyz.com/a/index.php
  2. If the url includes a path: xyz.com/abcde -> go to index.php on directory b and change the path to a param like so: xyz.com/b/index.php?id=abcde 如果URL包含路径: xyz.com/abcde- >转到目录b上的index.php并将路径更改为如下所示的参数: xyz.com/b/index.php?id=abcde

Both directories a and b are under the same root directory of course. 目录a和b当然都在同一根目录下。

I managed to do number 2, but I have no idea how to include rule 1. 我设法做到了2,但我不知道如何包括规则1。

You can use the following : 您可以使用以下内容:

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