Forum Moderators: phranque
I am starting a new forum and I created a subdomain and dropped my forums into it.
I would like to make sure that
Subdomain.mysite.com is the URL which is always displayed when the folder with the files loads. I specifically don't want this url to show EVER even if someone types it in directly:
www.mysite.com/subdomain_folder
that folder contains my forums but my hope is to obtain some rewrite/redirect commands in the htaccess file to ensure only URLs containing subdomain.mysite.com appear in SERPs.
Can anybody help?
I would also like to ensure that either the www version or the non-www version of the site gets indexed while not conflicting with the above commands.
The last and final thing I hope to accomplish is to make the index.php file from vbulletin to never appear in the URLs.
Its a tall order but I know we have some pros here!
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301]
Redirect /index.php http://subdomain.example.com/
RewriteCond %{THE_REQUEST} \/index.php\ HTTP
RewriteRule ^(.*)$ index.php$/$1 [R=301
[edited by: jdMorgan at 10:17 pm (utc) on Dec. 10, 2007]
[edit reason] example.com [/edit]
Rewrite the following URLs if typed into a browser OR if it is a link to my site somewhere on the Internet:
http://example.com/sub/
http://www.example.com/sub/
http://www.example.com/sub/index.php
to:
http://sub.example.com/
If someone types in http://sub.example.com/index.php, I would like it rewritten without the index.php:
http://sub.example.com/
If any one of the following domains have something after it, like:
http://example.com/sub/exterior-interior/how-to-make-a-blog.html
http://www.example.com/sub/exterior-interior/how-to-make-a-blog.html
Then the command would rewrite the URLs like so:
http://sub.example.com/exterior-interior/how-to-make-a-blog.html
[edited by: jdMorgan at 10:19 pm (utc) on Dec. 10, 2007]
[edit reason] example.com [/edit]
It's fairly difficult to address one or two problems, and even harder if the list keeps getting longer.
The subject of redirecting /index.blah to / has been discussed quite frequently here over the past year, and a search [webmasterworld.com] on WebmasterWorld threads would likely get you on-track toward addressing that problem.
Another basic fact is that what shows in the browser address bar and appears in search results is controlled by the links that appear on your pages. No amount of rewrite or redirect code can directly change that. So the first step is to make sure the links on your pages are correct, and then a bit of code can be used to accomplish any necessary "clean-up."
For more information, see the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com].
Jim
[edited by: encyclo at 1:30 am (utc) on Dec. 8, 2007]
[edit reason] fixed bbcode error [/edit]
Unfortunately, htaccess is so nuanced that even some people who are experts can get it wrong.
While I appreciate your direction to resources, none have been helpful with the specific set of issues I have faced.
BTW, my third post was merely a clarification of my original post. I had read EVEN MORE after posting the first time and realized I could sum it more succinctly. Since this forum prohibits editing a post, I had to repost.
I apologize for wasting your reading time.
EDIT: I NOW see that there is a way to edit by clicking a small little icon below my username.
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteRule .? http://www.example.com%{REQUEST_URI} [R=302,L] Now I need to figure out how to rewrite a link to the subfolder URL as a subdomain URL and rewrite URLs without the index.php. Getting this to mesh together seems one of the biggest challenges.
[edited by: jdMorgan at 10:08 pm (utc) on Dec. 10, 2007]
[edit reason] example.com [/edit]
how to get the www. forced so Google will not index any potential non-www sites
All you really need to do is write a directive so that requests for example.com without the www (example.com/)will return the www. root with a 301.
And also, a directive so that a request for the site with a filename after (index.php, index.htm,index.html) will likewise return www.example.com/ with the forward slash and not the filename. That part is right, but the first thing is getting the if/then logic of the process down, and making use of regular expressions to write the directives. A perfect thread for this situation is this one in the library:
Regular Expressions [webmasterworld.com]
That's how instructions are defined, but the basics for the logic are that the rewrite cond directive is setting up a condition so that, if the condition is met, the rewrite rule will be executed.
It's a huge help, in the beginning (like me), to learn to read regular expressions, character by character, to understand what they're saying in "geek shorthand" and then to write what's needed to be done in plain English pseudocode for yourself.
So it isn't: return www.example.com if anything other than www.example.com is requested (that would also exclude forum.example.com), it's simply:
>>If the URI requested is anthing with example.com
>>Then return that request to the User Agent including the www. in front of the example.com part of the URI.
Logic for the forum:
>>If the URI requested is in /forum/ (remembering that it's all relative to the root of the domain for .htaccess)
>>Then serve up forum.example.com
Then, trying to write the directives is hugely helped by having a printed out list of the symbols and characters, and also a printed out paper with some examples that are similar to what you want to do, as a model.
Someone will correct me if and where I'm wrong, but this is what I'm finding helpful as I'm hobbling along.
Added:
Some helpful searches:
redirect subdirectory to subdomain (at WebmasterWorld) [google.com]
redirect index.html to www (at WebmasterWorld) [google.com]
Using variations in wording for additional searches will bring up even more threads on the topics.
[edited by: Marcia at 6:40 am (utc) on Dec. 10, 2007]
In the meantime, I have decided to go with the following:
http://www.example.com/subfolder1/subfolder2/
Currently, I have learned how to rewrite the URL so that its formatted like so:
http://subfolder1.example.com/subfolder2/
OWNER EDIT (I was wrong, the following produces a loop I think)
Options -Indexes +FollowSymLinks
RewriteEngine on
RewriteRule ^subfolder1/(.*) http://subfolder1.example.com/$1 [R,L] When it is time, I will update the redirect to be a permanent redirect.
My next two items that I will work on are as follows:
1. As you pointed out:
write a directive so that requests for example.com without the www (example.com/)will return the www. root with a 301.
2. Remove index.php from a URL
I will continue to update this post as I go. I realize getting my end result will require the proper order of the rules.
[edited by: sfnet at 8:16 am (utc) on Dec. 10, 2007]
[edited by: jdMorgan at 10:21 pm (utc) on Dec. 10, 2007]
[edit reason] example.com [/edit]
Options -Indexes +FollowSymLinks
RewriteEngine on
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.html\ HTTP/
RewriteRule ^(([^/]+/)*)index\.html$ http://%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.php\ HTTP/
RewriteRule ^(([^/]+/)*)index\.php$ http://%{HTTP_HOST}/$1 [R=301,L] [edited by: jdMorgan at 10:21 pm (utc) on Dec. 10, 2007]
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301] Or is it the following take from your post here:
[webmasterworld.com...]
RewriteEngine On
RewriteCond %{http_host} ^example.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L] [edited by: jdMorgan at 10:22 pm (utc) on Dec. 10, 2007]
[edit reason] example.com [/edit]
Options +FollowSymlinks RewriteEngine on
RewriteCond %{HTTP_HOST} !^www¦subdomain1¦subdomain2\.example\.com
RewriteRule ^(.*)$ http://www.example.com/$1 [R=permanent,L]
This exempts specific subdomains. Seems like this could be the better choice. Maria, thoughts?
[edited by: jdMorgan at 10:23 pm (utc) on Dec. 10, 2007]
[edit reason] No URLs, please. See Terms of Service. [/edit]
Here is a completely-othodox example of the specific non-www to www redirect, with nothing missing and nothing extra -- by the book:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
Thank you very much.
I am stil learning a lot about how to write these statements.
My goal is to prevent two sites from being ranked in search engines.
When you begin the conditional with the ^ and there is no $ at the end, what is it doing? I am aware that ^ can mean two different things and I think the one most commonly used is to begin the regular expression.
^exact-match$ (fully-anchored)
^begins-with (start-anchored)
ends-with$ (end-anchored)
contains (un-anchored)
You'll also often see unanchored patterns posted that leave the code open to malfunction due to unexpected/unforeseen matches.
Jim
I suspect this is because I am not able to write or read the code well, and taking pieces of what other people write and expecting it to work properly is simply not possible. For that reason, I am really trying to learn this stuff.