Forum Moderators: phranque

Message Too Old, No Replies

RedirectMatch Alternative

         

mavenman

4:59 pm on Oct 7, 2005 (gmt 0)

10+ Year Member



I have the following url:

www.mydomain.com/mavenman

redirecting to

www.mydomain.com/id.php?id=mavenman

using

RedirectMatch ^/(.*[^\.php¦^\.jpg¦^\.gif¦^\.html¦^\.htm¦^/])$ [mydomain.com...]

My question is how can I keep this same working functionality but keep the originating URL in the clients browser location? I assume this needs to be some sort of internal redirection or masking but I have been unable to track down any solution.

TIA for your help!

Mavenman

jdMorgan

8:46 pm on Oct 7, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can use mod_rewrite to do an internal rewrite of the local URL-path to a different local URL-path.

This code, for use in .htaccess, approximates the function of your RedirectMatch:


Options +FollowSymLinks
RewriteEngine on
# If not php, jpg, gif, html, or html file request or directory request
RewriteCond %{REQUEST_URI} !(\.php¦\.jpg¦\.gif¦\.html?¦./)$
# rewrite the request to id.php with pathname in query string
RewriteRule (.*) /id.php?id=$1 [L]

Jim

mavenman

4:49 am on Oct 9, 2005 (gmt 0)

10+ Year Member



Thanks for the kickstart. Final resulting script worked like a charm for what I was looking for. Hope it helps others.

Options +FollowSymLinks
RewriteEngine on
# If not contains period or forwardslash in REQUEST_URI
#RewriteCond %{REQUEST_URI}!(\.php¦\.jpg¦\.gif¦\.html¦/)$
RewriteCond %{REQUEST_URI}!(\.¦\..*¦/)$
# rewrite the request to id.php with pathname in query string
RewriteRule (.*) /id.php?id=$1 [L]

This simple script in the .htaccess will grab any string that is appended to a top level domain that does not contain a period or a forwardslash (used to trap out filenames and directory calls). This is useful in allowing users to use simple URL's to pass items like usernames or product codes. I have a background id.php file that is processing the string. Once validated, I can process their request accordingly.