0

I was wondering how I could access domain.com/home from domain.com, I have asked this question before (One web page with multiple URL's using PHP) and i was told to use chdir() and include() but now I was wondering how I could this so that it would work with local .css files, as currently if I access "domain.com/home" when the head says "using style.css" it accesses domain.com/home/style.css as it should but however if i access domain.com it accesses domain.com/style.css as it is asking for a local file, changing all of the local file accesses is impractical as they are all drawing from a template using php includes so modifying one of them is inconvenient to do and not aesthetically pleasing in terms of code cleanliness.

If you do not fully understand what I am asking go to http://infinity-nova.com and http://infinity-nova.com/home too see the issue at hand. Is there any way to do this using htaccess? I am using an apachi server so i am able to use any url-rewriting plugins and what not that apachi has if that is necessary.

4

4 に答える 4

2

Your treating two different problems as the same thing. The location of your internal PHP scripts is one issue, looks like this has been resolved.

The browser being able to locate resources is a totally different matter, depending on how your application is setup.

If your application needs to be completely portable (loaded into any directory) then you need to create a baseUrl() function to use throughout your application.

Lets say you load you app into something.com/foo/bar/myapp where myapp is the root of your application. In your bootstrap (this is a script that runs before anything else, often to setup things like database connections) you must hardcore or otherwise determine the base URL your application is running in, an example:

$baseUrl = "/foo/bar/myapp";

Throughout the rest of your application you need to use this variable (if your application is object orientated a static function is also appropriate) like this:

<?php
<html>
  <head>
    <script src="<?= $baseUrl ?>/js/myscript.js"/>
    ...

MVC frameworks handle parsing this base URL differently and some come with a function to do it automatically, but the basic process is the same. When your page is rendered it will look like:

<html>
  <head>
    <script src="/foo/bar/myapp/js/myscript.js"/>
    ...

If you move your app you will also have to redefine the $baseUrl variable but all your paths will change accordingly.

于 2012-08-03T03:54:36.667 に答える
0

.htaccessファイルに次のように記述します。

Options +FollowSymLinks
RewriteEngine On
RewriteRule ^http://example.com*$ http://example.com/home/ [R=301,L]
于 2012-08-03T08:32:47.927 に答える
0

I don't quite understand, how you're having trouble with this.

Is /home/ where your assets are supposed to be? What's in your document root?

Have you tried rewriting the url domain.com/ to domain.com/home in apache/nginx.

于 2012-08-03T03:51:31.657 に答える
0

Well, I would just access stylesheet in both pages with absolute path like this

   <link rel="stylesheet" type="text/css" href="/home/style.php" />

And that should simply append domain to the beginning.

于 2012-08-03T04:07:42.747 に答える