TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 01-15-2009, 03:03 AM   #1 (permalink)
The Wanderer
 
kokjj87's Avatar
 
Join Date: Oct 2008
Posts: 18
Thanks: 0
kokjj87 is on a distinguished road
Default Need help of Mod Rewrite

Hi, i am trying to rewrite my url.
-the first rule will rewrite images/C.jpg to images/C.php.
But the second line of my mod rewrite would redirect all files except for(js, gif, jpg, png and css) to index.php.

The problem is, after my images/C.jpg is rewrite, the request will treat is as requesting a php file, and would be redirected to the index.php, so having a [L](Lock) would be useless too??

how do i solve this?

Thanks

I currently have this:
Code:
RewriteRule images/C.jpg images/C.php [NC,L]
RewriteRule !\.(js|gif|jpg|jpeg|png|css)$ index.php [NC,L]
And also Mod Rewrite, is really hard to debug. Is there any tools out there, that can help us to debug?
kokjj87 is offline  
Reply With Quote
Old 02-22-2009, 07:22 AM   #2 (permalink)
The Wanderer
 
Join Date: Feb 2009
Posts: 7
Thanks: 0
jlodell is on a distinguished road
Default

i use something along the lines of the following...

Code:
RewriteEngine on
Options FollowSymLinks
## IF 
## URL does not exist
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
## THEN
## Rewrite to bootstrap
RewriteRule ^(.*)$ index.php/$1 [PT,L,QSA]
jlodell is offline  
Reply With Quote
Old 02-22-2009, 04:06 PM   #3 (permalink)
The Frequenter
Newcomer 
 
xenon's Avatar
 
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 438
Thanks: 3
xenon is on a distinguished road
Default

@jlodell: he wants to deny access to an existing file, so your rules will have no effect there.

one quick fix would be to add images/C.php into the second's rule exception list, which should be a RewriteCond rule rather than a RewriteRule:

Code:
# your rules go here

RewriteCond $1 !(\.(?:js|gif|jpg|jpeg|png|css)|(?:images\/C\.php))
RewriteRule ^(.*)$ index.php/$1 [QSA,L]
ps: L in [L] stands for last rule, not lock.
ps2: ALWAYS escape characters other than letters and numbers in regex rules. just to be on the safe side.
__________________
I have optimistic thoughts, even though sometimes (if not always) life's a bitch.
xenon is offline  
Reply With Quote
Old 02-22-2009, 06:08 PM   #4 (permalink)
The Wanderer
 
Join Date: Feb 2009
Posts: 7
Thanks: 0
jlodell is on a distinguished road
Default

@xenon: you are right, but i'm just throwing out another approach on how to go about filtering with mod_rewrite. I honestly don't know what is going on with the C.jpg -> C.php but i don't see why that would imply that it is for denying access to a file?

Clarity...
What I really meant was, "Here is a basic start at a .htaccess file that shows a different approach to redirecting traffic thru a front controller."

Code:
RewriteEngine on
Options FollowSymLinks
## IF 
## URL does not exist
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
## THEN
## Rewrite to bootstrap
RewriteRule ^(.*)$ index.php/$1 [PT,L,QSA]
So then if you take your .jpg->.php rule and stick it in...

Code:
RewriteEngine on
Options FollowSymLinks

###### YOUR RULE ######
RewriteRule images/C.jpg images/C.php [NC]

## IF 
## URL does not exist
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
## THEN
## Rewrite to bootstrap
RewriteRule ^(.*)$ index.php/$1 [PT,L,QSA]
as long as C.php exists then everything is kosher.

2 cents:
I don't see the reasoning for the jpg->php change? I guess i am missing it or something. i realize that this will keep the image from getting served but wouldn't it be easier to just place it somewhere else instead of checking every request? Using this method it will NEVER get served to any request. It isn't like it is being filtered to only be served to a certain IP or what-not. It just seems a bit pointless, thats all.

good luck, justin
jlodell is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Mod Rewrite Made Easy CMellor Libraries & Extensions 12 12-14-2008 02:13 PM
Good 'ol mod rewrite help needed... h0ly lag XHTML, HTML, CSS 3 11-01-2008 05:52 AM
How to do ISAPI rewrite in zend framework (IIS) ? yusufeen Advanced PHP Programming 0 07-16-2008 12:26 PM
Mod Rewrite question (vb related) Brook General 1 01-20-2008 08:14 PM
mod rewrite - how to get title in url? Sam Granger Absolute Beginners 5 10-10-2007 02:58 PM


All times are GMT. The time now is 02:18 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design