Php 重写规则以获取url的最后两个参数

Php 重写规则以获取url的最后两个参数,php,.htaccess,mod-rewrite,Php,.htaccess,Mod Rewrite,好的,我有这个.htaccess文件,它获取base后面的第一个dir作为$1,第二个dir作为$2 <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond $1 ^[^\.]+[^/]$ RewriteRule

好的,我有这个.htaccess文件,它获取base后面的第一个dir作为$1,第二个dir作为$2

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d

    RewriteCond $1 ^[^\.]+[^/]$
    RewriteRule (.*) http://%{HTTP_HOST}/$1/ [R=301,L]

    RewriteRule ^([^/]+)/([^/]+)/$ index.php?sub=$1&page=$2 [L]
    RewriteRule ^([^/]+)/$ index.php?sub=$1&page=$1 [L]

    #RewriteRule ^(.*)/(.*)$ index.php?sub=$1&page=$2 [L]
    #RewriteRule ^(.*)$      index.php?sub=$1&page=$1 [L]
</IfModule>

重新启动发动机
重写基/
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写条件$1^[^\.]+[^/]$
重写规则(.*)http://%{http_HOST}/$1/[R=301,L]
重写规则^([^/]+)/([^/]+)/$index.php?sub=$1和page=$2[L]
重写规则^([^/]+)/$index.php?sub=$1&page=$1[L]
#重写规则^(.*)/(.*)$index.php?sub=$1和page=$2[L]
#重写规则^(.*)$index.php?sub=$1和page=$1[L]
现在我们需要在productionserver的子目录中测试这个网站。这将为url添加一个额外的目录

因此: hxxp://localhost/newwebsite/var1/var2/

有没有一种方法只获取url的最后两个参数,或者我应该直接插入它,它将按照我们想要的方式工作。(实际上不是一种选择)


谢谢

将htaccess文件放在
newwebsite
目录中,并将
RewriteBase/
更改为
RewriteBase/newwebsite/

,这样给出的
.htaccess
文件就是您已经拥有的文件,您想知道如何添加另一条规则来捕获目录
newwebsite
中的内容吗?