 |
Account Login
|
 |
 |
Latest Articles
|
 |
 |
IRC Channel
|
 |
 |
Associates
|
 |
 |
Associates
|
 |
|
 |
|
 |
|
 |
05-05-2008, 05:36 AM
|
#1 (permalink)
|
|
The Prestige
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
|
Escaping Metacharacters
I need to escape the '?' in RegEXP
Code:
RewriteRule ^image(?=this is where I want my '?')([A-Za-z0-9]+)?$ image.php?img=$1 [L]
I've tried many ways, none worked.
__________________
VillageIdiot can have my babbies ;d
|
|
|
|
05-05-2008, 06:10 AM
|
#2 (permalink)
|
|
is cute and cuddly
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
|
Using a backslash doesn't work? I escape periods in my rewrite's just like so \. with no problems. What about using QSA instead if it doesn't work? If I remember correctly you should be able to do
RewriteRule ^image$ image.php [QSA, L]
and it should work like /image?img=image.png => /image.php?img=image.png. Worst possible scenario you could do
RewriteRule ^image/([A-Z0-9]+)/?$ image.php?img=$1 [NC, L]
and site.com/image/image.png would pump it through your php file. According to this
though you should be able to escape with \... but I tried it and it wasn't working either, so I'm lost.
-m
|
|
|
|
05-05-2008, 06:18 AM
|
#4 (permalink)
|
|
The Prestige
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
|
Quote:
Originally Posted by delayedinsanity
Using a backslash doesn't work? I escape periods in my rewrite's just like so \. with no problems. What about using QSA instead if it doesn't work? If I remember correctly you should be able to do
RewriteRule ^image$ image.php [QSA, L]
and it should work like /image?img=image.png => /image.php?img=image.png. Worst possible scenario you could do
RewriteRule ^image/([A-Z0-9]+)/?$ image.php?img=$1 [NC, L]
and site.com/image/image.png would pump it through your php file. According to this
though you should be able to escape with \... but I tried it and it wasn't working either, so I'm lost.
-m
|
QSA gives me the 500 error, and NC does aswell.
__________________
VillageIdiot can have my babbies ;d
|
|
|
|
05-05-2008, 07:20 AM
|
#5 (permalink)
|
|
is cute and cuddly
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
|
Sorry, make sure there's no spaces. [QSA,L] or [NC,L]. QSA is for your query string, NC is just non case sensitive.
-m
|
|
|
|
05-05-2008, 07:24 AM
|
#6 (permalink)
|
|
The Prestige
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
|
Quote:
Originally Posted by delayedinsanity
Sorry, make sure there's no spaces. [QSA,L] or [NC,L]. QSA is for your query string, NC is just non case sensitive.
-m
|
Neither work, this is the same problem I get:
Code:
Not Found
The requested URL /image was not found on this server.
__________________
VillageIdiot can have my babbies ;d
|
|
|
|
05-05-2008, 09:33 AM
|
#7 (permalink)
|
|
The Acquainted
Join Date: Nov 2007
Location: Netherlands
Posts: 113
Thanks: 11
|
How does your whole .htaccess or .conf file looks like? Can you post it here?
|
|
|
|
05-05-2008, 09:34 AM
|
#8 (permalink)
|
|
The Prestige
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
|
Quote:
Originally Posted by sjaq
How does your whole .htaccess or .conf file looks like? Can you post it here?
|
nothing much actually, just RewriteEngine on, with a few RewriteRule's, and that one. so yeah
__________________
VillageIdiot can have my babbies ;d
|
|
|
|
05-05-2008, 09:37 AM
|
#9 (permalink)
|
|
The Acquainted
Join Date: Nov 2007
Location: Netherlands
Posts: 113
Thanks: 11
|
To clear things up what do you want to do exactly? It seems you want to rewrite /image/bla.jpg to /image.php?img=bla.jpg am I right?
|
|
|
|
05-05-2008, 09:38 AM
|
#10 (permalink)
|
|
The Prestige
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
|
Quote:
Originally Posted by sjaq
To clear things up what do you want to do exactly? It seems you want to rewrite /image/bla.jpg to /image.php?img=bla.jpg am I right?
|
no image?bla.jpg
__________________
VillageIdiot can have my babbies ;d
|
|
|
|
05-05-2008, 09:42 AM
|
#11 (permalink)
|
|
The Acquainted
Join Date: Nov 2007
Location: Netherlands
Posts: 113
Thanks: 11
|
This works on my computer
Code:
RewriteRule ^image([A-Za-z0-9\.\_]+)?$ image.php?img=$1 [QSA,L]
|
|
|
|
05-05-2008, 09:43 AM
|
#12 (permalink)
|
|
The Prestige
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
|
Quote:
Originally Posted by sjaq
This works on my computer
Code:
RewriteRule ^image([A-Za-z0-9\.\_]+)?$ image.php?img=$1 [QSA,L]
|
img=$1 doesnt work, I have it where it echos, for quick testing. so yeah, doesnt work. :[ and I have mod_rewrite enabled
I want it like image?bla.jpg, not imagebla.jpg
__________________
VillageIdiot can have my babbies ;d
|
|
|
|
05-05-2008, 09:48 AM
|
#13 (permalink)
|
|
The Prestige
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
|
Quote:
Originally Posted by sjaq
That's pretty strange

Just works
can you put print_r($_GET)); in your image.php file and post what happens..
|
o0okay
fsss
__________________
VillageIdiot can have my babbies ;d
|
|
|
|
05-05-2008, 09:50 AM
|
#14 (permalink)
|
|
The Prestige
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
|
I used var_dump instead of print_r, cause its more effective, and I got this:
:S
Update: I removed QSA, now it just gives me .php
__________________
VillageIdiot can have my babbies ;d
|
|
|
|
05-05-2008, 09:50 AM
|
#15 (permalink)
|
|
The Acquainted
Join Date: Nov 2007
Location: Netherlands
Posts: 113
Thanks: 11
|
But why don't you just use image/bla.jpg this looks much cleaner..
|
|
|
|
05-05-2008, 09:55 AM
|
#16 (permalink)
|
|
The Prestige
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
|
Quote:
Originally Posted by sjaq
But why don't you just use image/bla.jpg this looks much cleaner..
|
Sigh.. So let me guess, you can't find the answer?
__________________
VillageIdiot can have my babbies ;d
|
|
|
|
05-05-2008, 09:58 AM
|
#17 (permalink)
|
|
The Acquainted
Join Date: Nov 2007
Location: Netherlands
Posts: 113
Thanks: 11
|
No it seems apache doesn't allow ?'s in their regexes, even if you pass it in as a hex it doesn't work.. and when you use / it's pretty basic..
Code:
RewriteRule ^image/([A-Za-z0-9\.\_]+)?$ image.php?img=$1 [QSA,L]
|
|
|
|
05-05-2008, 10:00 AM
|
#18 (permalink)
|
|
The Prestige
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
|
Quote:
Originally Posted by sjaq
No it seems apache doesn't allow ?'s in their regexes, even if you pass it in as a hex it doesn't work.. and when you use / it's pretty basic..
Code:
RewriteRule ^image/([A-Za-z0-9\.\_]+)?$ image.php?img=$1 [QSA,L]
|
Well then, thats ass.. :P they need to update that. at least make it like this \? or [\?] or whatever
__________________
VillageIdiot can have my babbies ;d
|
|
|
|
05-05-2008, 10:05 AM
|
#19 (permalink)
|
|
The Acquainted
Join Date: Nov 2007
Location: Netherlands
Posts: 113
Thanks: 11
|
Ah I found it, when you use %3F it works, that is the hex for a ?. So that was the problem. It is just a technical restriction.. But you could fix it with php...
Code:
RewriteRule ^image$ image.php [QSA,L]
PHP Code:
// get all array keys $gets = array_keys($_GET); // check if it is a valid image (you may want to check if it exists $img = preg_match('/[a-zA-Z0-9\.\_]+/', $gets[0])? $gets[0] : null; // because it is a key apache replaces .'s with _'s we need to fix that $xp = explode('_', $img); $count = count($xp)-1; $ext = $xp[$count]; unset($xp[$count]); // the image $img = implode('_', $xp) . '.' . $ext;
|
|
|
|
|
The Following User Says Thank You to sjaq For This Useful Post:
|
|
05-05-2008, 03:28 PM
|
#20 (permalink)
|
|
Moderateur
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
|
I tried the following which seemed to work ok on my system:
RewriteCond %{QUERY_STRING} ^[a-z0-9]{1,20}\.(?:jpe?g|gif|png|bmp)$ [NC]
RewriteRule ^image$ img.php?img=%0 [L]
One thing to note is that your PHP file shouldn't be named the same as what comes before the query string, ie image?test.jpg should not use image.php because it appears that Apache's content negotiation gets in the way and serves up the PHP page without going through the rewrite process. Simply rename the PHP page to something else as I have in my example above, img.php
|
|
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|