Forum Moderators: phranque
Example:
[domain.tld...] = /home/domain.tld/htdocs
Rewrite:
[secure.provider.tld...] = /home/domain.tld/htdocs
I've developed a simple set of rules that will display the index page under the secured URI. The problem is while pre-processed includes (i.e., php includes) are rewritten correctly, I am having difficulties with the post-processed xhtml objects (i.e., images and css) not being rewritten correctly, getting 404 on the images and css directories.
Apache Log:
"GET /secure/domain.tld/ HTTP/1.1" 200 26209
"GET /css/domain.css HTTP/1.1" 404 297
"GET /images/domain.png HTTP/1.1" 404 300
My image and css references are relative links and all references are under a single root directory.
Example:
<img src="/images/domain.png" />
My goal is to put together a rewrite rule that will rewrite the entire root directory to include subdirectories. I would assume something like this would be quite basic. I would appreciate your suggestions and any examples would be great, too.
Thank you for your assistance.
Respectfully,
Gary
Welcome to WebmasterWorld [webmasterworld.com]!
> I would assume something like this would be quite basic.
Because of the fact that servers can be configured in endlessly-varying ways, that assumption is usually not correct.
You may post your code - with any domain-specific information replaced by "example.com" - if you're asking for help with it. However, in accordance with our charter [webmasterworld.com], we prefer not to write your code for you, but rather to help you write it.
Jim
Original URI = [domain.tld...]
Rewritten URI = [secure.provider.tld...]
RewriteEngine On
RewriteRule ^/secure/(.*\.+.*)/(.*) /home/$1/htdocs/$2
As I stated before, all pre-processed objects (i.e., php includes) are executed fine within the index file. It is the post-processed objects (i.e., images and css) that are getting the 404.
Any help would be greatly appreciated.
Respectfully,
Gary
In order to get to your secure server, you're going to need to do an external redirect:
RewriteRule ^/secure/([^.]*\.[^/]*)/(.*)$ https://www.secureprovider.tld/home/$1/htdocs/$2 [R=302,L]
I have shown a 302-Moved Temporarily redirect here, assuming that you don't want search engines to index the secure-server page, but rather, the page on your regular server. If you do want the secure page(s) indexed, use a 301.
Jim
My rule attempts to match the /secure/ subdirectory and then match any following string as long as it has at least 1 dot somewhere in it (i.e., a domain.tld).
Doing an external redirect is not my intention. I want to be able to securely or unsecurely access the same vhost's documentroot with a secure and unsecure URL.
I believe I discovered the reason for the post-processed objects (i.e., images and css) returning 404. I modified the src of each object to not include an initial slash.
Example:
<img src"images/domain.png />
This corrected the problem for the initial index page, but then opened a new can of worms for pages in deeper directories. My pages are dynamically generated with includes and uses the same src reference no matter how deep it goes into the site.
I believe what must be done is either find a way to dynamically change the virtualdocumentroot or use a include file before each of my post-processed objects to determine whether it is a http or https connection and for the URI accordingly. I would prefer the former.
I will begin a new thread which attempts to address it.
Respectfully,
Gary