Absolute Path for Deployment in a Non-Root Location

后端 未结 8 1302
耶瑟儿~
耶瑟儿~ 2021-01-06 13:22

I typically refer to any assets on my site using absolute path so that I don\'t have to worry about the location of the assets relative to current file.

<         


        
相关标签:
8条回答
  • 2021-01-06 13:32

    If you have a list of filename extensions that should be redirected, you might want to use the rewrite conditions using pattern matching againt the extensions.

    Another solutions is to simply create an /images directory under root and let images be downloaded from there. Or have there links to images in your path.

    0 讨论(0)
  • 2021-01-06 13:35

    Easy...

    # Assuming mod_rewrite is an option...
    <IfModule mod_rewrite.c>
       # Turn it on!
       RewriteEngine on
    
       # If path is /images/flag.png, connect to /holiday/images/flag.png
       RewriteBase /holiday/
    </IfModule>
    

    Assuming I'm understanding what you mean, this should do you just fine. Point of order, this .htaccess should be in /holiday/

    I do this locally on MAMP for testing a website that's base is in http://localhost:8888/SocialNetwork/ ... If I didn't have that, my absolute paths of, say, /profile would go to http://localhost:8888/profile/ instead of http://localhost:8888/SocialNetwork/profile

    0 讨论(0)
  • 2021-01-06 13:38

    try to add this to your .htaccess

    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^(www.)?DOMAINNAME.com$
    RewriteCond %{REQUEST_URI} !^/holiday/
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /holiday/$1
    RewriteCond %{HTTP_HOST} ^(www.)?DOMAINNAME.com$
    RewriteRule ^(/)?$ holiday/index.php [L]
    

    or take a look here - Changing the root folder via .htaccess

    0 讨论(0)
  • 2021-01-06 13:43

    what about using html's BASE element? http://www.w3.org/TR/html4/struct/links.html#h-12.4

    although i´m not sure how you could have it in a single html file and inherit it to the rest of your htmls, so your source remains intact. if your site is html-only maybe with frames, otherwise you could use some sort of server-side include depending on what youre using (asp, jsp, whatever). Check out this link for more information http://www.boutell.com/newfaq/creating/include.html

    0 讨论(0)
  • 2021-01-06 13:45

    I don't think this is gonna happen for you man, sorry.

    You have absolute paths in your documents, and want apache to prepend /holiday to them all without effecting the actual docroot? You can have one or the other, but not both.

    You need to either do a mass edit and prepend the directory yourself, or move your images/css/etc into the actual root directory.

    mod_rewrite is powerful, but can't really determine intent and parse the same url two different ways depending on what the user wants.

    Edit:

    I am wrong, but I don't have your answer. You may be able to use IS_SUBREQ in mod_rewrite to only apply the re-write conditions for sub-requests from your /holiday/index.php

    0 讨论(0)
  • 2021-01-06 13:49

    If you’re using Apache, there one rather simple thing you could do by just using an SSI variable in your paths. Do a global replace of all src="/ to something like

    src="<!--#echo var="prefix" -->/
    

    and then in your htaccess for the specific folder define the prefix variable as /holiday

    For sites that don’t have the variable or SSI, it’ll just show up as a comment or you can define it as an empty string.

    Of course this means you’ll have to turn on SSI in Apache.

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