really stumped at deny direct url

Discuss practical ways rearrange URLs using mod_rewrite.

really stumped at deny direct url

Postby azmo » Mon Jun 06, 2005 6:00 pm

Hi folks, I'm new here. I guess i'm somewhere between a newbie and intermediate mod_rewrite user, so I could really use some help on this one project I've been working on. I've got a rewritecond for 'test.php' which rewrites to a deny page if a query string is not met. If it is met, test.php is rewriten to test2.php with a env variable. The whole idea with the env variable is to make sure user goes to test2.php from test.php. How do I prevent a user from going directly to test2.php and bipassing the first page all together? One thing to clarify is, I "don't" want to pass the query string onto test2.php from test.php. That's why I dropped it in the last rewrite rule. Instead, I'm using the PHP getenv() in test2.php to grab the env. Help would be greatly appreciated since It's been killing me for the last two weeks and I can't seem to find any tuts on it. Here's what I got below:

Options +FollowSymlinks
RewriteEngine on
RewriteCond %{THE_REQUEST} test\.php [NC]
RewriteCond %{QUERY_STRING} !^string1=value$
RewriteRule ^test\.php http://my-domain.com/deny.html [L]
RewriteRule ^test2\.php - [E=passEnvVar:toTest2]
RewriteRule ^test\.php$ http://my-domain.com/test2.php? [R,L]

If any guru can give me a pointer, I can finally relax. Thanks.
azmo
 
Posts: 4
Joined: Mon Jun 06, 2005 5:15 pm
Location: California

Postby Caterham » Thu Jun 09, 2005 10:55 am

How do I prevent a user from going directly to test2.php
you're redirecting (external) to test2.php, this will turn out into a new request by the browser -> cannot be checked.

Use an internal redirect instead
Code: Select all
Options +FollowSymlinks
RewriteEngine on
# the_request not needed for test.php here
RewriteCond %{QUERY_STRING} !^string1=value$
RewriteRule ^test\.php$ http://my-domain.com/deny.html [L]

#How do I prevent a user from going directly to test2.php,
# only possible, if internal redirect used to test2.php below
RewriteCond %{THE_REQUEST} test2\.php [NC]
RewriteRule ^test2\.php /test.php [R,L]

RewriteRule ^test\.php$ /test2.php? [L,E=passEnvVar:toTest2]
Caterham
 
Posts: 690
Joined: Fri Dec 10, 2004 1:30 pm

Postby azmo » Thu Jun 09, 2005 4:46 pm

Your a genious caterham! :biggrin: However, in order to pass the env variable along to php, I had to use;

#had to toss this line in
RewriteRule ^test2\.php - [E=passEnvVar:toTest2]
#and take out the env from the flag below in order for php to grab it
RewriteRule ^test\.php$ test2.php? [L]

Instead of your suggestion on the env variable. For some reason PHP won't pick up the env variable unless it's written as above.
Again, many thanks!
azmo
 
Posts: 4
Joined: Mon Jun 06, 2005 5:15 pm
Location: California


Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: No registered users and 22 guests

cron