Forum Moderators: phranque
Sorry that my first post is a request.
My problem: I'm trying to add a query string to a subdomain. It's one specific query string, so there's no mass regex matching or anything.
[subdomain.mysite.com...]
to
[subdomain.mysite.com...]
my last failed attempt (one of many):
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{THE_REQUEST} \/index.php\ HTTP
RewriteRule index.php index.php\?id=elephant [L,R=301]
index.php is in the root of the subdomain
Any help greatly appreciated
Be aware that no escaping is required on the "/" in the RewriteCond pattern, but that literal periods and spaces should be escaped in both the RewriteCond and RewriteRule patterns. In addition, your patterns should be start- and end-anchored when possible using "^" and "$". For example, your ruleset should be something like this:
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /index\.php\ HTTP/
RewriteRule ^index\.php$ index.php?id=elephant [R=301,L]
Unfortunately, none of these tweaks are likely to 'fix' your current problem because they just improve the 'specificity' of your patterns to prevent unexpected/undesirable operation.
Also be aware that www.subdomain.domain.com is a sub-sub-domain. You might consider sticking with the 'usual' best practices, using the 'www' subdomain or just domain.com for your main site, and subdomain.domain.com for your subdomains; I'd hate to have to read those sub-sub-domain URLs over the phone or on the radio, for example, and the www on the front end is just wasted bytes.
Jim
[edited by: jdMorgan at 9:36 pm (utc) on Dec. 15, 2009]
The tweaks stopped the browser seizing up, but no redirection happened. I just stayed at the same page.
The .htaccess file is in the same folder as index.php
I've had a look at subdomains on other sites and they don't use the www (e.g. taxes.about.com, shop.nike.com) but would removing the www make any difference?
Is it just that realistically this is too complicated to do?
Try getting rid of that backslash preceding the "?" in the RewriteRule substitution URL -- I missed it on the first pass (See the code correction in my previous post).
Next completely-flush (delete) your browser cache (remember to always do this after any change to any code on your server), and then test again.
Also, just for clarity, this code goes into the .htaccess file in the same top-level directory as the index.php file for that subdomain -- Yhat is, in the same folder as the subdomain's "home page." If the code is in the wrong location, it either won't get executed or the RewriteRule pattern won't match.
As I stated, "www.subdomain.domain.com" is a waste of bytes and typing, might confuse the search engines, and is unnecessary. It will also interfere with 'branding' your site.
While these may not seem so important now, you are at most risk if your site is successful. You may join the legion of posters in the Google forum asking, "How many months does it take Google to re-index my site and pick up all my new URLs" or "How come Yahoo! keeps trying to index my site by just the domain name and no subdomains?"
Like all of us, you will likely rely on search engines for traffic, and anything you can do to make your site straightforward and simple for them to index (i.e. avoid triggering obscure bugs in their software) will be beneficial. Run a super-tight ship on your server (e.g. use specific patterns and pattern-anchoring as I previously mentioned, force domain canonicalization, avoid duplicate-content, etc.), and preclude the majority of problems we discuss here at WebmasterWorld right from the start. Never accept sloppiness for convenience, and always think long-term (unless your site is intended to be temporary). :)
Jim
What I also did was try a header(location:http://subdomain.mysite.com/?id=elephant) in index.php just as a test, with the .htaccess deleted, and t the browser threw up 'Firefox has detected that the server is redirecting the request for this address in a way that will never complete'
Navigating directly to the url from the address bar works fine, however. Don't know if that means anything.
Is it because I'm trying to redirect from index.php to index.php, with only the addition of a query string?
So the question remains, "Why doesn't your .htaccess code get executed, and if not, why not?"
Try a simpler rule, just as a test:
Options +FollowSymLinks
RewriteEngine on
#
RewriteRule .* http://www.google.com/ [R=301,L]
If that works, then there's some detail of the URL-path or query string that's not right in your original code.
Jim