当你转到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=$1 [L,QSA]
但不起作用。我该怎么做呢?
发布于 2018-06-02 04:06:52
将此规则放在subdir/.htaccess
(不是站点根目录)中:
RewriteEngine On
RewriteBase /subdir/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .+ index.php?param=$0 [L,QSA]
发布于 2018-06-03 06:22:36
谢谢你,阿努巴瓦!首先,我编辑/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=$1 [QSA,L]
最后在/subdir/index.php中
我获得的值paramvalue为:
$myParamValue = $_GET["param"];
echo myParamValue
它返回: paramvalue
https://stackoverflow.com/questions/50650172
复制相似问题