Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Software
User Name
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.


  Search this Thread
Old 10-28-2009, 06:23 AM   #1
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:
RewriteCond %{HTTP_HOST} ^$ [OR]
RewriteCond %{HTTP_HOST} ^$
RewriteRule ^index.html\/dll\/c\/(.*)$ "http\:\/\/www\.mydomain\.com\/index\.php\/$1" [R=301,L]
in this case the URL: will be redirected

Ex 2: The following doesn't
RewriteCond %{HTTP_HOST} ^$ [OR]
RewriteCond %{HTTP_HOST} ^$
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: 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 07:17 AM. Reason: SOLVED
Old 10-28-2009, 10:31 AM   #2
Registered: Jun 2007
Posts: 152

Rep: Reputation: 37
try using the the generic . instead of \?
Old 11-05-2009, 04:37 AM   #3
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:
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:

and I wanted it to become:

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 ""

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.
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.


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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 10:00 AM
htaccess redirection eldojoseph Linux - Server 9 08-02-2008 12:28 PM
Apache regex kinetik Linux - General 2 08-15-2006 06:31 PM
APACHE: AliasMatch not work, regex not right? tclwp Linux - Software 1 03-16-2005 02:27 PM
Redirection in Apache gonzo22 Linux - Networking 5 02-12-2005 10:54 AM > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 09:22 AM.

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