问题
I have this dir structure on my webpage:
rootOfweb/services/oneservice/service1.php
rootOfweb/services/oneservice/service2.php
rootOfweb/services/anothersercice/service1.php
rootOfweb/services/anothersercice/service2.php
www.example.com/index.php?sideID=nameOfService&p=services/oneservice/service2
I have this code in php including files thats needed:
<?php
if(isset($_GET["p"]))
{
$side = $_GET["p"];
include ($side.'.php');
}
?>
I have diffrent names on the diffrent subdirs and i have made one mod_rewrite that work on one of the conditions:
RewriteRule ^([a-åA-Å0-9_!-]+)/([a-åA-Å0-9_!-]+)$ index.php?sideID=$1&p=services/oneservice/$2
The aboue rule work for the first service (rootOfweb/services/oneservice/ -all service files -)
I need to create a rule that can work on all subdirs.
回答1:
Following on from from discussion in comments section above you can have rewrite rules like this:
RewriteEngine On
RewriteBase /
RewriteRule ^([\w!-]+)/([\w!-]+/[^/]+/[\w!-]+)/?$ index.php?sideID=$1&p=$2 [L,QSA,NC]
This will support URLs like these:
http://example.com/services/subdir/2014/subfile1
http://example.com/services/subdir/2013/subfile2
http://example.com/services/subdir123/2010/subfile234
回答2:
You should be able to just change your regex:
RewriteRule ^([a-åA-Å0-9_!-]+)/([/a-åA-Å0-9_!-]+)$ index.php?sideID=$1&p=subdir/$2
来源:https://stackoverflow.com/questions/26531221/how-to-make-dynamic-mod-rewrite-for-subdirs