Closed Thread Icon

Preserved Topic: Apache mod_rewrite directives. (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=21205" title="Pages that link to Preserved Topic: Apache mod_rewrite directives. (Page 1 of 1)" rel="nofollow" >Preserved Topic: Apache mod_rewrite directives. <span class="small">(Page 1 of 1)</span>\

 
jiblet
Paranoid (IV) Inmate

From: Minneapolis, MN, USA
Insane since: May 2000

posted posted 12-04-2001 18:38

Okay Apache gurus, what I want to do is add a set mod_rewrite directives that when a non-existent *.html file is requested, it serves up the equivalent *.php file.

I would try to figure this out myself, but I don't have access to the Apache config, and my sysadmin is too busy to experiment with things, so I don't think this will get done unless I can come with a complete solution that he just needs to paste into the httpd.conf.

-jiblet

mr.maX
Maniac (V) Mad Scientist

From: Belgrade, Serbia
Insane since: Sep 2000

posted posted 12-04-2001 20:04

Instead of mod_rewrite it would be better to create server-side script that would be set as ErrorDocument 404 handler...

Anyway, if you want to do it with mod_rewrite, the following code should do the trick.

RewriteEngine on
RewriteCond&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/jiblet/%{REQUEST_FILENAME}&nbsp;&nbsp;&nbsp;&nbsp;!-f
RewriteRule&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;^(.*)\.html$&nbsp;&nbsp;&nbsp;&nbsp;/jiblet/$1.php

You can add this to the .htacsess file. Also, you must specify path relative to server root (the example from above will only handle files located inside http://server/jiblet/ folder, all other folders - incl. subfolders - must be handled separatively). Oh, and .htaccess file must be located in the same folder that is specified in rewrite directives.

BTW Instead of mod_rewrite you should really consider ErrorDocument handler, like I said at the top...


jiblet
Paranoid (IV) Inmate

From: Minneapolis, MN, USA
Insane since: May 2000

posted posted 12-04-2001 23:42

Very cool. I must admit I'm confused why you think a server side script 404 handler would be better, but I will take your advice.

Also, the server is not shared. I am the owner of the entire directory structure which includes 4 name based virtual hosts. Aside from the fact that .htaccess is disabled by default, I wanted a global solution anyway. You see the whole circumstance developed because we replaced our 3-year old hacked and cracked mandrake install with RedHat. In the process we switched to name-based virtual hosts rather than IP-based. For some reason this made Apache unable to parse .html files for PHP (go figure) which I use on every single page. So we wrote a script that changed all 300+ .html files to .php and all local links ending in .html to .php.

Everything is cool locally, but we are getting tons of 404s from old links and search engines. A ErrorDocument handler does seem to make more sense now that I think about it. One question for you though... if a similarly named .php file does not exist, what would be the proper way to 'pass' the error so that all proper headers are generated and whatnot...

-jiblet

mr.maX
Maniac (V) Mad Scientist

From: Belgrade, Serbia
Insane since: Sep 2000

posted posted 12-05-2001 00:55

When .php version of file doesn't exist, send 404 error through HTTP header, like this:

header ("HTTP/1.0 404 Not Found");

You can also create your own error page which will be shown instead of Apache error page.


Pugzly
Paranoid (IV) Inmate

From: 127.0.0.1
Insane since: Apr 2000

posted posted 12-05-2001 00:58

I'm not aware of Apache not being able to parse files just because it's name based and not IP based. Our servers support both. We run the LAMP comb (Linux, Apache, MySQL, PHP). Can't say as I've done it to parse .html files for PHP code, we do do it to parse .htm files for SSI code. With name based and IP based sites on the same servers, we don't run into any problems.

jiblet
Paranoid (IV) Inmate

From: Minneapolis, MN, USA
Insane since: May 2000

posted posted 12-05-2001 17:12

yeah pugz, I thought it was a bit fishy myself. How can name-based virtual hosts suddenly break file parsing for certain extensions? But when you have a sysadmin as good as mine, you learn to pick your battles, because he gets things done better than you ever could.

-jiblet

« BackwardsOnwards »

Show Forum Drop Down Menu