Welcome to WebmasterWorld Guest from 54.145.39.186

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

how to match question mark in RedirectMatch?

     

vasanth

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



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

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

pls suggestion give me.

thank u

phranque

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

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



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.

vasanth

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

lucy24

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

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



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.

vasanth

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



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

vasanth

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?

Code:
RewriteEngine on

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


Thank u

lucy24

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

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



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
www.example.com/~abcd/optional-more-stuff-here
to
www.example.org/targetpage

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

vasanth

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



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

Code:
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

g1smd

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

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



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.

lucy24

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

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



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.

vasanth

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



sorry..

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

lucy24

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

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



In English.

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

g1smd

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

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



Is there a question mark in the requested URL?

lucy24

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

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



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):
[webmasterworld.com...]
http://www.webmasterworld.com/apache/4345903.htm#msg4355756

JD_Toims

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

WebmasterWorld Senior Member Top Contributors Of The Month



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.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month