htaccess rewrite redirect with parameters in subfolder

后端 未结 2 759
执念已碎
执念已碎 2021-01-24 10:26

I want that when you go to url: http://www.example.com/subdir/paramvalue

redirects to

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

My .htacce

相关标签:
2条回答
  • 2021-01-24 10:44

    Thanks anubhava ! First i edit 000-default from /etc/apache2/sites-available/ and add:

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

    Then the solution in .htaccess was:

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

    Finally in /subdir/index.php

    I get the value paramvalue as:

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

    it returns : paramvalue

    0 讨论(0)
  • 2021-01-24 10:50

    Place this rule in subdir/.htaccess (not site root):

    RewriteEngine On
    RewriteBase /subdir/
    
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule .+ index.php?param=$0 [L,QSA]
    
    0 讨论(0)
提交回复
热议问题