Mod Rewrite Hide Folder

后端 未结 3 1868
庸人自扰
庸人自扰 2020-12-09 22:21

I think this is a pretty simple question.

How do you an apache rewrite to hide a folder.

EX: www.website.com/pages/login.php to www.website.com/login.php

相关标签:
3条回答
  • 2020-12-09 22:38

    I know the original post here was from a couple years ago, but it's been coming up first in the search engine, so maybe this will help others looking to hide a folder name in the URL.

    Not exactly what original poster wanted, but along the same lines.

    RewriteCond %{HTTP_HOST} ^mydomainname\.com$ [OR]
    RewriteCond %{HTTP_HOST} ^www\.mydomainname\.com$
    RewriteCond %{REQUEST_URI} !^/subfoldername/
    RewriteRule (.*) /subfoldername/$1
    

    The above example would redirect any request to mydomainname.com or www.mydomainname.com to the subfoldername directory in the root directory for the domain, and the subfolder name would not appear in the URL.

    0 讨论(0)
  • 2020-12-09 22:47

    If your example actually reflects the files you need, then in your .htaccess file:

    #Options +FollowSymLinks
    RewriteEngine On
    
    RewriteRule ^/pages/(.+)\.php $1\.php [NC, L]
    

    Also, if the directory has read permission, it cannot be, in reality "hidden". I assume you mean that it no longer appears in the url.

    0 讨论(0)
  • 2020-12-09 22:48

    I assume what you want is for the browser to request /home.php but the server to actually use the file located at /pages/home.php, right? If so, this should work:

    Make sure the apache mod_rewrite module is installed. Then, use something like this in your apache config, virtual host config, or (less desirable) .htaccess file:

    RewriteEngine On
    RewriteRule ^/(.*)$   /pages/$1
    

    The rules use regular expressions, so you may want to look at a reference on that topic if you're unsure. Read the manual for more info on other directives (RewriteCond can be very useful) or rule options.

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