htaccess 使用子文件夹中的参数重写重定向

htaccess rewrite redirect with parameters in subfolder

当你去url时我想要那个: http://www.example.com/subdir/paramvalue

重定向到

http://www.example.com/subdir/index.php?param=paramvalue

我的 .htaccess 文件是:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^subdir/(.*)   subdir/index.php?param= [L,QSA]

但是不起作用。我该怎么办?

将此规则放在 subdir/.htaccess(不是站点根目录)中:

RewriteEngine On
RewriteBase /subdir/

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .+ index.php?param=[=10=] [L,QSA]

谢谢阿努巴瓦! 首先,我从 /etc/apache2/sites-available/ 编辑 000-default 并添加:

<Directory "/var/www">
    AllowOverride All
</Directory>

那么 .htaccess 中的解决方案是:

RewriteEngine On
RewriteBase /subdir/

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?param= [QSA,L]

终于在 /subdir/index.php

我得到值 paramvalue 为:

$myParamValue = $_GET["param"];
echo myParamValue 

它 returns : 参数值