Apache 2 mod_rewrite and PHP. Modify $_SERVER['REQUEST_URI'] value from htaccess?

前端 未结 1 1573
一整个雨季
一整个雨季 2021-01-04 18:37

I have this .htaccess file:

RewriteEngine On

RewriteRule ^hello$ goodbye

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


        
相关标签:
1条回答
  • 2021-01-04 19:21

    First of all you made a mistake of not putting L or PT flag in your first rule. Your code should be like this:

    RewriteRule ^hello$ goodbye [PT]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} !=/favicon.ico
    RewriteRule ^ index.php [L]
    

    Once that code is there access this variable in index.php:

    $_SERVER["REDIRECT_URL"]
    

    This will have value: /goodbye

    EDIT

    If you have mod_proxy enabled on your host, you can have your first rule as:

    RewriteRule ^hello$ /goodbye [P]
    

    And then you will have: $_SERVER["REQUEST_URI"]=/goodbye

    0 讨论(0)
提交回复
热议问题