Use a subdirectory as root with htaccess in Apache 1.3

后端 未结 3 1179
感动是毒
感动是毒 2020-12-22 19:43

I\'m trying to deploy a site generated with Jekyll and would like to keep the site in its own subfolder on my server to keep everything more organized.

Essentially,

相关标签:
3条回答
  • 2020-12-22 19:53

    Finally got it, after a week of trying. RewriteRules really are voodoo…

    RewriteEngine On
    
    # Map http://www.example.com to /jekyll.
    RewriteRule ^$ /jekyll/ [L]
    
    # Map http://www.example.com/x to /jekyll/x unless there is a x in the web root.
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} !^/jekyll/
    RewriteRule ^(.*)$ /jekyll/$1
    
    # Add trailing slash to directories within jekyll
    # This does not expose the internal URL.
    RewriteCond %{SCRIPT_FILENAME} -d
    RewriteRule ^jekyll/(.*[^/])$ http://www.example.com/$1/ [R=301]
    

    No need for DirectorySlash. It magically all works.

    0 讨论(0)
  • 2020-12-22 19:59

    The only simple solution worked for me is here

    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^domain-name.com$ [NC,OR]
    RewriteCond %{HTTP_HOST} ^www.domain-name.com$
    RewriteCond %{REQUEST_URI} !folder/
    RewriteRule (.*) /folder/$1 [L]
    

    Put this code into your .htaccess file.

    domain-name.com – Type your own domain name

    folder – Type the name of the subfolder which has the test/development website

    0 讨论(0)
  • 2020-12-22 20:01

    You can simply use:

    RewriteBase   /jekyll
    

    And everything starts from that point.

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