URL rewrite htaccess


URL rewrite htaccess

我有一个小网站,在那里我写了一些规则

RewriteEngine On
RewriteRule ^[!/.]*([A-Za-z0-9]+)/?$ /index.php?id=$1 [NC,L]

这会将我的所有链接重定向到example.com/index.php。而我希望他们重定向所有具有一个目录example.com/dir的URL,将其重定向到此链接example.com/index.php,以及具有两个目录的URL,example.com/dir1/dir2应重定向到example.com/index2.php,其余不应重定向。

您可以使用以下代码。。我会稍微解释一下。。

http://www.example.com/customdir/index/1/

customdir=您的子目录

index=index.php

1=您的id

Options +FollowSymLinks
RewriteEngine on
RewriteRule customdir/('w+)/?('d+)?/? customdir/$1.php?id=$2