Forum Moderators: phranque

Message Too Old, No Replies

htaccess question mark issue

         

neoo

5:32 pm on Mar 10, 2011 (gmt 0)

10+ Year Member



Hello

I want to redirect subdomain.domain.com/?article to subdomain.domain.com/index.php.
What I tried :
RewriteEngine on
RewriteCond %{HTTP_HOST} ^subdomain.domain.com$
RewriteRule ^\%3Farticle$ "http\:\/\/subdomain\.domain\.com" [R=301,L]

And it's not working . Thanks.

neoo

5:56 pm on Mar 10, 2011 (gmt 0)

10+ Year Member



Also I tried :
RewriteRule ^(.*)article(.*)$ "http\:\/\/subdomain\.domain\.com" [R=301,L]

But it's also not working....

jdMorgan

7:36 pm on Mar 17, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



1. RewriteRule cannot "see" query strings; it examines only the requested URL-path. Use a RewriteCond.
2. The literal periods in the pattern to match your subdomain must be escaped as shown.
3. The subdomain pattern should not be end-anchored in case it is requested as an FQDN or with a port number appended. in either case, this would cause an end-anchored pattern to fail.
4. This pattern should be case-insensitive for the same reason.
5. The RewriteCond testing the subdomain is only required if this .htaccess file is shared with other subdomains and/or your main domain.
6. No characters except for "$" and "%" in the RewriteRules substitution need to be escaped.
7. A trailing "?" is required to remove the original query string. Otherwise, it is passed through the rule by default. This question mark functions as an operator, and *will not* appear in the redirected-to URL.

RewriteEngine on
#
# externally redirect subdomain.domain.com/?article to subdomain.domain.com/index.php
RewriteCond %{HTTP_HOST} ^subdomain\.domain\.com [NC]
RewriteCond %{QUERY_STRING} ^article$
RewriteRule ^$ http://subdomain.domain.com/? [R=301,L]

Jim

[edited by: jdMorgan at 4:50 am (utc) on Mar 18, 2011]

g1smd

8:26 pm on Mar 17, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



8. Never redirect to index.php as a URL. The canonical URL for the site root is www.example.com/ with a trailing slash. The code above is already correct.