Forum Moderators: phranque

Message Too Old, No Replies

Testing mod rewrite using .htaccess

         

justgowithit

10:06 pm on Jul 18, 2006 (gmt 0)

10+ Year Member



I’m trying to use .htaccess for mod_rewrite and was wondering if there’s a simple way to test if it is working prior to me banging my head against the wall tweaking regex.

I’m aware of test code for mod_rewrite via httpd.conf…. Is there similar code for using .htaccess?

Any help is greatly appreciated.

jdMorgan

10:15 pm on Jul 18, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sure, try a simple rule in your top-level .htaccess file:

Options +FollowSymLinks
RewriteEngine on
RewriteRule ^foo\.html$ /path_to_page_that_exists.html [L]

Request the page "foo.html" from your domain, and the server should respond by serving up the page that actually exists.

Note that the "Options" line may not be needed. Or it may not be allowed. Or it may be required -- Depends on your server configuration.

Jim

justgowithit

1:21 am on Jul 19, 2006 (gmt 0)

10+ Year Member



Thanks Jim,

For some reason I keep getting a 404 error. I tried this on three different hosts, one of which I know is configured properly for sure. For someone who picks things up quickly this mod_rewrite stuff sure seems like voo-doo to me....

jdMorgan

1:52 am on Jul 19, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Change it to do an external redirect. Then you can see what happens (if anything) in your browser address bar:

Options +FollowSymLinks
RewriteEngine on
RewriteRule ^foo\.html$ http://www.example.com/path_to_page_that_exists.html [R=301,L]

Jim

justgowithit

2:31 am on Jul 19, 2006 (gmt 0)

10+ Year Member



Ah Ha - that worked! Jim, you’re the magician to this voo-doo. Thank you for your help. If you couldn’t tell, I’m new to mod_rewrite ;).

Just out of curiosity; why did the internal link throw a 404? Will I still be able to use this technique to clean up my dynamic URLs for this (less than desirable) host?