/filename.html to /filename.php and cgi-bin too....

New to mod_rewrite? This is a good place to start.

/filename.html to /filename.php and cgi-bin too....

Postby joecoolest » Sun Jul 19, 2009 10:47 pm

I've spent the better part of 2 hours searching and reading these forums and the Apache doc's links... and I am now thoroughly confused. :D

If someone could help me with a couple of soup to nuts example for two of my redirects maybe I can take these and expand them for the rest of my needs.

What I am doing is replacing some pages/scripts with new php versions. I'd like to rewrite the URL's rather than simply add HTML redirects. So the users will have a more seamless transition.

scenario 1 ( a simple one):
http://www.domain.com/file.html -> http://www.domain.com/file.php

scenario 2 (a more complex one):
http://www.domain.com/cgi-bin/script.cg ... ata=123456 -> http://www.domain.com/new.php?data=123456

Any help would be appreciated... I really want to learn this stuff and I think maybe just some examples that apply to my real world situations might be the catalyst to me moving forward.

Thanks in advance.
joecoolest
 
Posts: 1
Joined: Sun Jul 19, 2009 9:56 pm

Postby richardk » Mon Jul 20, 2009 4:28 pm

/cgi-bin/script.cgi?index=file.txt?data=123456

index=file.txt?data=123456 or /cgi-bin/script.cgi?index=file.txt&data=123456?

Code: Select all
Options +FollowSymLinks

RewriteEngine On

# Make sure the PHP file exists.
RewriteCond %{DOCUMENT_ROOT}/$1php -f
RewriteRule ^(.+\.)html$ /$1php [QSA,L]

# Match the data value.
RewriteCond %{QUERY_STRING} data=([^&]+)(&.*)?$ [NC]
RewriteRule ^cgi-bin/script\.cgi$ /new.php?data=%1 [QSA,L]

The cgi-bin rule might need moving to the cgi-bin directory (with RewriteEngine On and cgi-bin/ removed).
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Beginner's Corner

Who is online

Users browsing this forum: No registered users and 29 guests

cron