homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

how to match question mark in RedirectMatch?

 2:06 pm on Sep 4, 2013 (gmt 0)

RedirectMatch ^/([a-zA-Z]{4}+\?+)/$ [twitter.com ]

In browser: press enter need to redirect twitter.com...That four letters working good but adding question mark not working..

pls suggestion give me.

thank u



 2:15 pm on Sep 4, 2013 (gmt 0)

a question mark in the url indicates the start of the query string.
you cannot match the question mark using RedirectMatch.

use RewriteCond (mod_rewrite) to examine THE_REQUEST.


 2:32 pm on Sep 4, 2013 (gmt 0)

when I use RewriteCond already i need old files then write new domain..But I don't have old files...Just I give a parameters needs to redirect to some other page...

Like /usa?sample-India this value sample..like coming randomly That parameter values just we redirect to some other page...This values just file name..not query string


 9:21 pm on Sep 4, 2013 (gmt 0)

1. Question marks cannot occur in the path of the URL. Anything after the question mark is, by definition, a query.

2. mod_alias (Redirect by that name) doesn't do query strings. For that you need mod_rewrite (RewriteRule with [R] flag)

Earlier posts suggest you don't like this answer. But where Apache is concerned, you can dislike things until the cows come home. The facts won't change :(

A redirect of any kind-- mod_alias, mod_rewrite, php script-- isn't about "old" files and "new" files. It's about "pattern" and "target". A request is compared against the pattern; if it matches, the rule points to the target. Ordinarily the rule doesn't know and doesn't care whether either of the two physically exists.


 5:08 am on Sep 5, 2013 (gmt 0)

ok..I will try in RewriteRule..Thank u:)


 6:25 am on Sep 5, 2013 (gmt 0)

I tried this rewriteRule but nothing happen just four letter i need to forward to some pages..Anything i need to add?

RewriteEngine on

RewriteRule ^/~([a-zA-Z]{4}+)/ [twitter.com...] [R]

Thank u


 7:00 am on Sep 5, 2013 (gmt 0)

This is happening in htaccess, right? Leave off the leading / in the pattern.

The flag should be [R=301,L]. The [R] by itself defaults to 302. And always include [L] unless you've got a specific reason to leave it out.

Remember www.example.com

{4}+ doesn't make sense. Just {4}. But if you don't need to exclude requests that fit the pattern except for being too short or too long, you can use + alone.

Note that as written, the rule redirects all requests in the form

Are you sure that's what you want? How many URLs currently fit the pattern?


 7:15 am on Sep 5, 2013 (gmt 0)

six URL pattern i finished...
And also last one also ok

RewriteEngine on

RewriteRule ^/([a-zA-Z]{4}+)/?(.*)$ http://www.twitter.com/ [R]

Now It's working.

clearly what i want after question i need to do some regular expression match i need to do that's it..This is also okay for me..

Thank u


 8:07 am on Sep 5, 2013 (gmt 0)

The code still has several errors, which will be apparent if you test a number of requests.

I suspect that you need {4,} in place of {4}+

/? - means "optional slash". It has nothing to do with testing for a question mark.

The trailing (.*)$ is completely redundant.

If you are wanting to test for a question mark and everything that comes after it, you must add a preceding RewriteCond looking at either %{THE_REQUEST} or %{QUERY_STRING}.

Use example.com in this forum to prevent URL auto-linking.


 8:32 am on Sep 5, 2013 (gmt 0)

It may help if you go back and explain in English* exactly what the requests looks like before they get redirected. Is there a short list of specific URLs? Or is there a large group of potential URLs that all fit into some pattern?

* I realize this is not your native language. But your English is better than my Hindi, Bengali or Punjabi. Trust me on this.


 8:36 am on Sep 5, 2013 (gmt 0)


RewriteEngine on

RewriteRule ^/([a-zA-Z]{4}+)/?(.*)$ [twitter.com...] [R]

clearly what i want after question mark(?) i need to do some regular expression match..


 7:55 pm on Sep 5, 2013 (gmt 0)

In English.

FIRST we establish exactly what you want to do. THEN we work out the code to get there.


 11:53 pm on Sep 5, 2013 (gmt 0)

Is there a question mark in the requested URL?


 12:40 am on Sep 6, 2013 (gmt 0)

I think there must be, because the first post in this thread had

RedirectMatch ^/([a-zA-Z]{4}+\?+)/$ et cetera

Hm. Is it possible those plusses are intended for .+ i.e. not "more of this character" but "more stuff after this character"?

:: uneasy recollection of someone once posting in this forum because their boss wanted to use literal question marks in filenames* ::

... and that's why we like to start out getting a grip on the problem in English before writing the first syllable of code.

* Thought I'd have to call on phranque, but here it is (with and without fragment):


 1:44 am on Sep 6, 2013 (gmt 0)

Okay, it looks like there's a necessary condition here based on the title of the thread, and since there are multiple attempts posted let's see if this does the trick:

RewriteCond %{QUERY_STRING} .?
RewriteRule ^([a-z]{4})/?$ http://www.twitter.com/ [NC,R=301,L]

In a URL a ? indicates information to be sent to the file being requested [in regular exressions, unless the ? escaped EG \? it mean 0 or 1 of the preceding]. A ? in a URL is not part of the file path itself, so the server won't ever look for the file abcd?.php, it will only look for the file abcd and if it's present the server will make the variable .php [as well as any information following an =] available to the file being processed.

RedirectMatches and RewriteRules only match the file being requested. They do not try to match the information sent to the file to be processed, so they don't "see" a ? in a URL.

To match a ? followed by anything [or nothing or not present in this case] in a request, we need to check the file requested with a RewriteRule and then use a Condition [RewriteCond] to check for [in this case it appears optionally] a literal ? followed by anything or nothing and redirect even if a ? is not present.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved