Forum Moderators: phranque

Message Too Old, No Replies

I want redirect from within subdomain to root

Do I use a rewrtite or redirect?

         

Icarion

5:01 pm on Apr 13, 2010 (gmt 0)

10+ Year Member



I have a folder named /controller/ which store.domain.com points to. there are links within this folder that refer to files that are in main root domain.com

I want all requests for store.domain.com/page.htm to go to
domain.com/page.htm

When I do such a request it says:
"Not Found
The requested URL /page_shows.htm was not found on this server."
This is error:

Error: File does not exist: /var/chroot/home/content/e/e/m/eemktg/html/controller/page.htm

store.domain.com points to html/controller

this is what I have:
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteRule store.domain.com/(.+)\.htm$

[domain.com...] [QSA,R=301]

Please advise.

jdMorgan

6:21 pm on Apr 13, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



RewriteRule only sees the local URL-path. It cannot 'see' domains or query strings. So you need a RewriteCond to check the requested hostname.

Options +FollowSymLinks
RewriteEngine on
RewriteBase /
#
RewriteCond %{HTTP_HOST} ^store\.example\.com
RewriteRule ^(.+)\.htm$ http://www.example.com/$1.htm [R=301,L]

Note also that [QSA] is not needed unless you append additional query string data; Otherwise, the query string will pass through this rule without being changed, and [QSA] is not needed (and is wasteful of processing time).
Similarly, you do not need "RewriteBase /" unless you have previous code that has set the rewrite base to a non-default value. Consider disabling MultiViews and directory Indexes in your Options statement -- for security and efficiency reasons.

Jim

Icarion

1:00 pm on Apr 14, 2010 (gmt 0)

10+ Year Member



Thank you!
How do I use this for redirecting calls for images/*.gif, jpg, png and .js and .css.

Eg.

Call to store.example.com/images/page.gif I want to go to
example.com/images/page.gif

It seems also that my reference to ../mm_menu.js from store.example.com gives me this:The requested URL /javascript:; was not found on this server.

Also, do you have some good tutorial sites on htaccess configs?

jdMorgan

2:14 pm on Apr 14, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can modify the rule above to match all of those paths using a "local OR" in the RewriteRule pattern, and back-referencing the entire path:

RewriteCond %{HTTP_HOST} ^store\.example\.com
RewriteRule ^((.+\.(html?|css|js))|images/[^.+]\.(gif|jpe?g|png))$ http://www.example.com/$1 [R=301,L]

Be aware of a very important point. Do not rely on this code to "make your site work," because these redirects force the visitor's browser to make two requests for every page and object they try to fetch. This slows down your site (which Google now measures) and it makes a mess of your logs and tracking data -- every request is doubled. Instead, be sure your pages themselves link to the proper URLs and use this code only to speed up the replacement of old incorrect URLs in search engines.

Redirects cannot be used as a "quick fix" to correct basic on-page linking errors.

Be very sure that you understand the effects of these redirects on your site's performance, ranking, and maintainability and on the validity or your 'stats' for traffic analysis...

Another point that you bring up: Apache .htaccess code affects only HTTP requests. It will have no effect on 'file includes' that reference only the local filesystem. Therefore, if you are doing a 'file include' on mm_menu.js, you will need to be copy that file or symlink it into the correct fileapace, because .htaccess cannot fix this problem. If instead you are linking to that file in a <script> tag, then use a server-relative (starts with a slash and the full server filepath) or an absolute URL, instead of trying to use a page-relative URL-path.

[added] Some good tutorials, references, and examples are cited in our Apache Forum Charter, and in our Apache Forum Library. See the links at the top of this page. [/added]

Jim