How to hide params passed in url using .htaccess

前端 未结 3 1847
天命终不由人
天命终不由人 2020-12-06 03:12

I have a peculiar situation, my website is like

www.example.com/page.php?url=homepage
. I am trying to use .htaccess file to make url look like

www.examp         


        
相关标签:
3条回答
  • 2020-12-06 03:49

    Try this:

    <IfModule mod_rewrite.c>
    Options +FollowSymlinks
    RewriteEngine on
    RewriteBase /
    
    # /anything/anything -> anything.php?url=anything
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^([A-Za-z0-9_])/([^/]*)$ /$1.php?url=$2 [L]
    
    </IfModule>
    

    If the page.php filename will always be the same, then do it like this:

    <IfModule mod_rewrite.c>
    Options +FollowSymlinks
    RewriteEngine on
    RewriteBase /
    
    # /page/anything -> page.php?url=anything
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^page/([^/]*)$ /page.php?url=$1 [L]
    
    </IfModule>
    
    0 讨论(0)
  • 2020-12-06 03:55
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^page/(.*)/$ /page.php?url=$1 [L]
    
    0 讨论(0)
  • 2020-12-06 04:08

    This code you can hide you page name

    RewriteRule    ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$  pagename.php?name=$1&id=$2    [NC,L] 
    
    0 讨论(0)
提交回复
热议问题