0

I think I've gone through a million articles and everyone's codes on this, but I just can't get it to work! Every code I try works but it shows the redirect url instead of the virtual one.

I would like mysite.com/company/client/ to actually show the results from mysite.com/company/client.php, but the files within client.php become broken unless I make absolute links.

For instance mysite.com/company/css/style.css is broken when viewing from http://mysite/company/client/, but is working fine when going to the real file mysite.com/company/client.php

I hope someone knows how to solve this problem without having to change all links in client.php to absolute!

Thanks!

Scott

scott
  • 1,068
  • 1
  • 9
  • 20
  • 1
    Please provide some code from your .htaccess file. Show us some of your code from the actual page the links are breaking on as well. – Michael Irigoyen Jun 24 '11 at 13:50

1 Answers1

1

You might want to consider the HTML BASE tag:

...
<head>
...
<base href="http://mysite/company" />
...
</head>
...

You put this in the client.php file, then any relative link & reference is automatically "converted" to an absolute one, starting from the right folder.


See the comments on possible issues with the BASE tag. Another option would be to perform a redirect instead of a rewrite, by adding "[R]" to the RewriteRule. However, then your users will see the "client.php" in the URL.

HelmuthB
  • 471
  • 3
  • 10
  • It is highly advised not to use the `` tag if other options are available due to caveats it introduces. For example, the `` tag will break all hyperlinks pointing to anchors (``). Since his behavior is being caused because of a rewrite rule, there will be a way to address it via the .htaccess file. **EDIT**: This question actually has some good information on the `` tag's problems: http://stackoverflow.com/questions/1889076/is-it-recommended-to-use-the-base-html-tag – Michael Irigoyen Jun 24 '11 at 13:55
  • The base does look like a good start! It seems to fix everything! Thanks very much for your replies. Yes I hope that there can be a solution that will work 100% of the time, for now I will use base. – scott Jun 24 '11 at 14:00
  • @scott Edit your question to include samples of your code so we can try to assist you further. – Michael Irigoyen Jun 24 '11 at 14:20
  • @michael-irogoyen, there isn't really anything to show because I dont have a working htaccess statement; I'm just looking for that way in which I can make that client/ virtual folder show the contents of client.php without ruining the links. What I have right now in my htaccess is `code` RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.php\ HTTP/ RewriteRule ^(([^/]+/)*)index\.php$ http://mysite.com/company/$1 [R=301,L]`code` – scott Jun 26 '11 at 07:20