url issues, need to redirect 3 urls but the codes i've tried arent working - apache

I know nothing about code sadly but i'm hoping that you can help. I've tried asking my web designer but he claims he doesn't know what a 301 redirect is and have noticed his own site has canonicalization issues.
I need to redirect the 3 urls below to www.mydomain.co.uk
www.mydomain.co.uk/index.html
mydomain.co.uk/index.html
mydomain.co.uk
I have never used ftp before, but have downloaded filezilla tonight so i can try fix this and have made a .htaccess file as my site didnt seem to have one.
I have browsed (almost) the whole internet looking for answers to this solution and have tried some codes suggested in previous posts on here but they didn't seem to do anything.
If you need to know, i think my server is apache.

I hope your site isn't built using HTML.. However, using your .htaccess you could try:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.mydomain\.co\.uk [NC]
RewriteRule ^(.*)$ http://www.mydomain.co.uk/ [R=301,L]
This should be sufficient enough to force the www If you need to force the index.html you would do:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.mydomain\.co\.uk [NC]
RewriteRule ^(.*)$ http://www.mydomain.co.uk/$1 [R=301,L]
It's been a while, but both of these should sufficient to do what you want...
I think it's time to find a new developer, because the one you have sounds like a complete idiot.

Related

301 Redirect Whole Site Except One Folder, leave Add-on domains alone

I have a brainteaser and need help from people smarter than me. I have a shared hosting account. I'd like to 301 forward the root URL (say, domain.org) to a new URL. I also want one folder (/blog/) to be left alone (not forwarded). I was able to find an example of this here, and I put together this potential scenario for doing that:
RewriteCond %{REQUEST_URI} !^/blog/
RewriteRule ^(.*)$ http://newdomain.org/$1 [L,R=301]
I believe that this should be OK, but here's the trick: I have add-on domains in this hosting, and if I use the above, I'm pretty sure that I will forward every one of them to newdomain.org, not just domain.org. I did some testing using more specific text strings in the first spot following RewriteRule, but I can't seem to get the syntax without blowing up my site and getting a 500.
Any ideas would be greatly appreciated!
Thanks, Dave
Try adding another condition:
RewriteCond %{HTTP_HOST} ^domain\.org$ [NC]
RewriteCond %{REQUEST_URI} !^/blog/
RewriteRule ^(.*)$ http://newdomain.org/$1 [L,R=301]
Where domain.org is the domain that you want everything to be redirected to newdomain.org, except /blog/.

mod_rewrite redirect specific .asp pages back to original server

I need to redirect traffic for a section of a redeveloped site back to the original site with apache mod_rewrite rules. I need to redirect all requests starting with http://www.example.com/page.asp back to the original site http://www.original.com/page.asp with the query string or anything following page.asp intact.
This seems simple enough, however I have had no luck with mod_rewrite generators or documentation on the web. My latest stab at the problem looks like this:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^http://www.example.com$ [NC]
RewriteRule ^page\.asp(.*)$ http://www.original.com/page\.asp$1 [R=301,NC]
I appreciate any insight into correcting this mod_rewrite rule. Other redirects are working fine.
I was able to get the rewrite to function properly using:
RewriteRule ^/page(.+) http://www.original.com/page$1 [R=301,NC,L]
I found this apache doc helpful: Resource Moved to Another Server

mod_rewrite for IE6 to static page on webserver

Our new website does not work in IE6 and honestly we wont make it work as its <1% of our traffic. I want to serve up a page that lives on the webserver that will be served up when a user comes to the site in IE6. What would be the best way to achieve this? It would be great if someone can provide a code snippet also.
I was able to get the redirect working by using this:
RewriteCond %{HTTP_USER_AGENT} MSIE\ 6
RewriteRule ^(.*)$ /general/notsupported.html [L,R]
However, i wanted to also mask the url so if someone comes in on www.example.com/uri/querystring it will stay there but serve up a page saying "Sorry" ie6 is not supported.
Thanks in advance!
Something like this should do it:
RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} whatever_the_ie6_user_agent_string_is
RewriteRule .* /path/to/your/static/page [R]

.htaccess mod_rewrite 301 redirect with nested exceptions?

I need a little help with my .htaccess before I deploy it!
I want to 301 redirect almost everything from elementalthreads.com to ethreads.com, excluding blog/wp-content/uploads, and /pommo.
Am I doing this right?:
RewriteEngine on
#exclude old uploads folder and /pommo
RewriteCond %{REQUEST_URI} !^/(blog/wp-content/uploads|pommo) [NC]
RewriteRule (.*) http://ethreads.com/$1 [R=301,L]
Will that transfer canonical pagerank?
Here's where I know I need help:
The old site has a wordpress blog, which I've cloned on the new domain. I'd love to preserve the permalinks, which are almost 1:1, eg:
http://www.elementalthreads.com/blog/ethreads-now-on-amazon-com/ redirects to
http://ethreads.com/ethreads-now-on-amazon-com/ (note /blog/ is missing here)
And the blog index http://www.elementalthreads.com/blog/ should redirect to http://ethreads.com/blog/, which seems like an exception to the above rule, since "/blog/" should only be preserved here?
I'm stumped about how to regEx or otherwise define these last two conditions/rules. Any help would be most appreciated!
That looks correct to me. However, you should not put this live without checking it, there really is nothing preventing you from being able to test it. One thing to bare in mind is that browsers can cache 301 response codes so when testing you should use [R,L] as your flags. Once you are happy add the [R=301,L] back in before deployment.
OK for points (1) & (2)
# only redirect the blog direcotry
RewriteRule ^blog/?$ http://ethreads.com/blog/ [NC,R=301,L]
# redirect all sub folders of blog to the new domain
RewriteRule ^blog/([\w-])/?$ http://ethreads.com/$1/ [NC,R=301,L]

Using .htaccess to reroute all requests through index.php EXCEPT a certain set of requests

So I just inherited a site. The first thing I want to do is build a nice little standard, easy-peezy, CMS that allows for creating a page with any URL (for example: whatever.html).
Therefore, if user hits example.com/whatever.html, it should get any db info for whatever.html and display it. This is run of the mill stuff.
My problem is that there are quite a few pages on the site (all listed in the .htaccess) that need to continue to be accessible. For instance, /Promotions is linked to promotions.php via .htaccess, and I need it to stay that way.
Anyone know how I can construct the .htaccess file to allow specific rewrites to still work but to reroute all other requests through index.php?
Currently, I just have .htaccess show a custom 404 page which in turn checks the db for the url and displays it if it exists. This is an easy solution, but I know that some people have weird browser toolbars (dumb or not, they exist :) ) that autoredirect 404s, and I'd hate to annoy my users with these toolbars by not allowing access to certain pages.
Thanks so much for your help!
The RewriteRule for promotions should still work as it's not 404ing.
If the 404 handler is showing the page because it exists in the database then it should really be returning a 200 OK status (overriding the 404 one), so you should not get any issues with browser toolbars.
As for doing the rerouting you can do something like this:
RewriteEngine On
RewriteCond %{REQUEST_URI} !^.*/(promotions|anotherone|somethingelse)($|/.*$) [NC]
RewriteRule ^(.*)$ /index.php?p=$1
Here is another variant:
RewriteEngine on
RewriteRule ^/i/(.*)$ - [L]
RewriteRule ^/css/(.*)$ - [L]
RewriteRule ^index.php$ - [L]
RewriteRule ^(.*)$ index.php?p=$1 [L,QSA]