LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 10-28-2009, 05:23 AM   #1
angel115
Member
 
Registered: Jul 2005
Location: France / Ireland
Distribution: Debian mainly, and Ubuntu
Posts: 542

Rep: Reputation: 79
Thumbs up [SOLVED] Apache .htaccess RewriteRule '?' (question mark character) using regex


Hello There,

After checking the apache doc and several forums on the subject I still didn't manage to redirect the character '?'

Ex 1: The following is working fine:
Code:
RewriteCond %{HTTP_HOST} ^mydomain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.mydomain.com$
RewriteRule ^index.html\/dll\/c\/(.*)$ "http\:\/\/www\.mydomain\.com\/index\.php\/$1" [R=301,L]
in this case the URL: http://www.mysite.com/index.html?fra...p/f/myfile.zip will be redirected
to: http://www.mysite.com/index.php?download=myfile.zip


Ex 2: The following doesn't
Code:
RewriteCond %{HTTP_HOST} ^mydomain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.mydomain.com$
RewriteRule ^index.html\?frameA\=zip\/c\/(.*)$ "http\:\/\/www\.mydomain\.com\/index\.php\?letter\=$1" [R=301,L]
In this case if I type the URL: http://mydomain.com/index.html?frameA=zip/c/myfile nothing happen. It's like if my string didn't match (but it does)

and each time is the same, all my redirections are working fine except the one with a question mark.

Any idea why?

Last edited by angel115; 08-30-2010 at 06:17 AM. Reason: SOLVED
 
Old 10-28-2009, 09:31 AM   #2
SethsdadtheLinuxer
Member
 
Registered: Jun 2007
Posts: 152

Rep: Reputation: 37
try using the the generic . instead of \?
 
Old 11-05-2009, 03:37 AM   #3
angel115
Member
 
Registered: Jul 2005
Location: France / Ireland
Distribution: Debian mainly, and Ubuntu
Posts: 542

Original Poster
Rep: Reputation: 79
Thumbs up

Hi SethsdadtheLinuxer

Thanks for you reply but that doesn't work.

After few more hours I finaly found the solution

and here it is:
Code:
RewriteCond %{QUERY_STRING} ^frameA\=zip\/[a-z]\/(.*)$
RewriteRule ^index\.html(.*)$  /index.php?search=%1  [L]
I explain

Here is how my original URL look like:
http://www.mysite.com/index.html?fra...p/f/myfile.zip

and I wanted it to become:
http://www.mysite.com/index.php?download=myfile.zip


So when you have a ? in your Original URL you need to use %{QUERY_STRING} in RewriteCond to check if it match what you are expecting and to gather the elements that you want with "()"

In my example I was interested to know which file the visitor was trying to access and keep it for later to be able to rebuild the new URL. In my example it was "myfile.zip"

Now the problem I've got was "how to use my pattern in memory and past it into my new url?". I was trying to access with the dollar sign "$" as I though it should be (like in normal Regex) but no, you need to to use the "%" sign to use the pattern stored in memory from the previous line the $ sign will return the pattern sored in memory from the same line.
Ex:
Code:
RewriteRule ^(index)\.html$  /($1).php  [L]
in the above example the $1 will hold the value 'index'.

so I use %1 and here it is, it retrieved the value put in memory the line just above.

Well I'm not sure if I was clear in my explaination but I hope that will help few people out there, as this one give me few good hours of testing before to get the expected result.


enjoy
Angel.

Last edited by angel115; 08-30-2010 at 06:24 AM.
 
  


Reply



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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Subdomain Redirection Using htaccess And mod_rewrite On Apache For Linux Or Uni LXer Syndicated Linux News 0 02-27-2009 09:00 AM
htaccess redirection eldojoseph Linux - Server 9 08-02-2008 11:28 AM
Apache regex kinetik Linux - General 2 08-15-2006 05:31 PM
APACHE: AliasMatch not work, regex not right? tclwp Linux - Software 1 03-16-2005 01:27 PM
Redirection in Apache gonzo22 Linux - Networking 5 02-12-2005 09:54 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 03:16 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration