Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Archive /

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, biapar, Willr, Ingo, simon_w

mod_rewrite experience


Reply


1288 Views

Avatar
toopy

Community Member, 8 Posts

24 May 2008 at 9:10pm

Edited: 24/05/2008 9:27pm

I had a mod_rewrite problem with my ss-web-site that resides on a shared Apache-host.

When installing SS in a subfolder like /<my-website>/silverstripe/ SS did not work at all.

When installing SS without subfolder like /<my-website>/ SS did work more or less for short URLs like http://<my-website>/admin.

With long URLs that use many /Parameters/ like an Ajax-Request that loads the Image-Uploading-Form into a StaffPage-Image-Tag of the CMS, I got JS-errors and the Page-Not-Found-Page was loaded in place of the requested form.

By comparing this with a properly working SS-installation on a Wampserver I found that it had to do with the way that Apache (Php?) delivers some $_SERVER-fields that SS evaluates on every request (both installations in subfolder /silverstripe). Rewrite takes place in both installations but:

With Windows-Wamp-Apache-Server:
$_SERVER["SCRIPT_NAME"] shows the rewritten URL /silverstripe/sapphire/main.php
.
$_SERVER["ORIG_SCRIPT_NAME"] is not set
.
In main.php the $baseURL is calulated to: /silverstripe which is correct
.
With shared Apache-Host:
$_SERVER["SCRIPT_NAME"] shows /silverstripe/admin (not rewritten)
.
$_SERVER["ORIG_SCRIPT_NAME"] shows the rewritten URL /silverstripe/sapphire/main.php
.
In main.php the $baseURL is calulated to: / which is NOT correct
The following line in main.php fails to return the proper $baseURL
.
...
// Get the request URL
$baseURL = dirname(dirname($_SERVER["SCRIPT_NAME"]));
...

Now it works perfectly after inserting a bit of code
before the $baseURL-calculation line in sapphire/main.php
but I do not know wheter this is correct in every case.

...
if (isset($_SERVER["ORIG_SCRIPT_NAME"])) {
$_SERVER['SCRIPT_NAME']= $_SERVER["ORIG_SCRIPT_NAME"];
}
.
// Get the request URL
$baseURL = dirname(dirname($_SERVER["SCRIPT_NAME"]));
...

May be this can help