Page 1 of 1

Using 'clean' URLs with PHP/Apache on Win32

Posted: Tue Feb 27, 2007 2:31 pm
by mjseaden
Hi,

On one of my previous sites, I created 'clean' urls, using PHP scripts without extensions (using ForceType in .htaccess), by creating extensionless scripts on my web public root directory, and reading the incoming $REQUEST_URI for any additional parameters. For example, a forward slash followed by a 'fake' directory name e.g. extensionless php script name: 'admin';

if you type 'admin/addrecord' then

Code: Select all

explode( '/', $REQUEST_URI )
would contain 'admin' and 'addrecord', hence you would go to the 'addrecord' page.

The actual script was just 'admin', but it looks as if you are going to the 'admin' directory and running 'addrecord'. I make the script act according to the parameters after the script name.

I've had this working before, but now when I try it on my new Apache 2.0.58, PHP 5, Win32 system on a new site, it runs the correct script but all of the images don't display properly, even though checking the paths of the images in the browser points to the same image. My sessions also appear not to work with anything after the base script name.

Is this a problem unique to Win32, as when I had it working it was running on Linux, or is there something I must be missing?

Many thanks

Posted: Tue Feb 27, 2007 2:35 pm
by Kieran Huggins
You should be using either only directory names in the URL (defaulting to index.php) OR mode_rewrite to achieve clean URLs IMO

Posted: Tue Feb 27, 2007 2:43 pm
by AKA Panama Jack
You might want to enable MultiViews in Apache. MultiViews is normally disabled and you have to enable it if you want to avoid using extensions in URLs.

Example:
<Directory />
Options Indexes FollowSymLinks Includes ExecCGI MultiViews
AllowOverride None
Order deny,allow
Deny from all
</Directory>
The effect of MultiViews is as follows: if the server receives a request for /some/dir/foo, if /some/dir has MultiViews enabled, and /some/dir/foo does not exist, then the server reads the directory looking for files named foo.*, and effectively fakes up a type map which names all those files, assigning them the same media types and content-encodings it would have if the client had asked for one of them by name. It then chooses the best match to the client's requirements.

Posted: Tue Feb 27, 2007 3:13 pm
by mjseaden
Hi AKA & Co,

I've tried the 'MultiView' option in my <Directory> directive for htdocs, however that doesn't seem to be improving matters.

Both my <img...> tags, and my <link...> tags (which include my CSS in the <head>) are not working with something after the script (like /addrecord).

It specifically seems to be the <img...> and <link...> tags that don't seem to be working - strangely though they still seem to point at the correct absolute URLs when you view the image path in the browser.

I was actually incorrect, my sessions are still working, so that doesn't seem to be a problem.

I'll keep looking....

Posted: Tue Feb 27, 2007 3:19 pm
by mjseaden
Got it - my <img..> and <link...> tags are having the script name added to their directory sequence after htdocs. So the path is now http://localhost/admin/img/myimage.jpg, instead of http://localhost/img/myimage.jpg so they're not working.

Is there any solution to this without resorting to horrible absolute URLs which make moving the site extremely inconvenient?

Posted: Tue Feb 27, 2007 3:24 pm
by mjseaden
Fixed - I added a leading '/' to my <link..> and <img...> tag url addreses...so /css/admin.css rather than css/admin.css.

It now correctly identifies the path of the files.

Many thanks.