簡體   English   中英

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=$1 [L,QSA]

但不起作用。 我能怎么做 ?

將此規則放在subdir/.htaccess (不是站點根目錄)中:

RewriteEngine On
RewriteBase /subdir/

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .+ index.php?param=$0 [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=$1 [QSA,L]

最后在/subdir/index.php

我得到值 paramvalue 為:

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

它返回:paramvalue

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM