Calling a file with PHP keeping local URLs of called file
i have two files:
1.- root/folder/folder/themes/themeindex.php
and
2.- root/index.php
I want to include themeindex.php
in index.php
so when you enter to root
directory, it will load the theme without taking you to (or showing you) the root/folder/folder/themes/
path.
I'm struggling to find or figure out a way to include the themeindex.php
file but keeping the URLs local to its themes
folder.
Meaning my
<link rel="stylesheet" type="text/css" href="sty开发者_StackOverflowle.css" />
will remain as that and I won't have to turn it into:
<link rel="stylesheet" type="text/css" href="/folder/folder/themes/style.css" />
I hope this all makes sense.
EDIT: Hopefuly this explanation of my reasons helps a bit more...
1.- I want the final developer to be able to create themes as intuitively as possible. So, the URLs remain as simple and intuitive as possible.
2.- I need to include the active theme into the
root
directory, so it autoloads when theroot
is opened.So if you combne, my reason number one, with my reason number two, then you might understand how important it is for URLs to remain local and easy to understand.
Instead of style.css you could request style.php, a file you define that uses imports root/folder/folder/themes/style.css
and echoes it outright.
you can give a base tag in your code and point it to: the folder where you have the css files.
http://www.w3schools.com/tags/tag_base.asp
In root .htaccess file, add next lines:
RewriteEngine On
RewriteRule ^style.css$ /folder/folder/themes/style.css [L]
To include the theme file is simple:
include('root/folder/folder/themes/themeindex.php');
The other issue is specific to HTML. HTML needs to have the web path (not the absolute path) to the file so it can load it and use it.
The best you can probably do is something like:
<link
rel="stylesheet"
type="text/css"
href="<?php echo $theme_dir; ?>style.css"
/>
but that will still expose your theme directory. Why are you trying to hide that directory?
Response to comment:
If you take the code I have above and let your developer know how to structure their own content directory. All you would need to do it keep track of something like $active_theme_root
and echo that out to load their own customized theme. As far as I know, you cannot set an HTML include directory, so HTML will need to know the web path to all needed assets
Best solution may be to have them use a global stylesheets folder for all themes ("root/stylesheets"). They would then link to this global folder in a relative manor:
<link rel="stylesheet" type="text/css" href="stylesheets/mytheme/style.css" />
精彩评论