Redirect root to page for jquery tabs - .htaccess

I've got a site using jQuery Tools tabs and Ajax. It works fine if you start out at the home page:
http://bdbcreative.com/home.htm
Click on any of the tabs and you get the extended Ajax address, which is what client wants and seems to be necessary for jScrollPane to work (http://bdbcreative.com/home.htm#web-design.htm).
But if someone just enters the domain - http://bdbcreative.com - "home.htm" never gets written and I end up with a URL like http://bdbcreative.com/#web-design.htm, which breaks jScrollPane.
I'm thinking I can use .htaccess to fix this, but I can't figure out the syntax. Can someone point me in the right direction. For consistency's sake, I'd like to have any site root URLs (http://bdbcreative.com or http:www.bdbcreative.com/ etc.) redirect to the home.htm address (i.e., http://bdbcreative.com/home.htm)
Thanks - Joe

After trying umpteen thousand examples, I found one that did what I needed.
For the .htacess file:
RewriteEngine on
RewriteRule ^$ http://www.bdbcreative.com/index.htm [R=301,L]
Hope this helps someone else.
Best - Joe

Related

How to redirect a URL?

I have a problem in redirecting a URL on a Silverstripe website. I have a news feed page with a summary of articles in a paginated style. It displays 20 articles initially and switches to the next 20 based on the page number chosen. It is just the standard blog layout. When I click on page 2 then it should navigate to https://*****/news/?count=20 and for page 3 as https://*****/news/?count=40 etc. However upon clicking the blog page number it navigates to https://*****/news/news/?count=20. So the navigation link is not rewriting the parent URL.
All of my other Silverstripe websites work fine with the same blog layout except this and I don't see any reason to tweak the default code. I thought of adding a .htaccess redirect like this
Redirect 301 /news/news/?start=20 https://******/news/?start=20
but I didn't have any luck to make it work. Kindly suggest me a solution for this.
The output I expect is to redirect to the right URL
https://******/news/?start=20
Here is a simple redirection rule that should fix the symptom you describe:
RewriteEngine on
RewriteRule ^/?news/news/(.*)$ /news/$1 [R=301,L]
But I doubt that approach is a good idea. Simply because it tries to fix a symptom, not the cause. The cause is that you actually create requests to URLs that contain the /news/news/ issue which should never happen. I assume the cause of that issue is that you hand out relative references (so something like news/...) instead of absolute references (/news/...). I strongly suggest that you handle the cause instead of trying to fix the symptom.

htaccess - Is this Correct?

Have looked through various articles both here and elsewhere but
could do with confirmation regards the way I have set up htaccess.
RewriteEngine On
RewriteCond %{HTTP_REFERER} orange [NC,OR]
RewriteRule .* blocked.php [L]
Can someone please confirm that given the code above that it will
block any domain, subdomain or page with the word orange in it?
It looks to be working but I need to ensure that I have covered all
bases and that I am blocking any link from or any image hotlinked from
my site where there is orange anywhere in the domain.
BTW I thought that if I have only one condition that I can leave out
the ,OR but when I removed it then it did not work in the test I was
doing??? Anyone know why this would not work without the ,OR ??
Many thanks in advance!
Can someone please confirm that given the code above that it will block any domain, subdomain or page with the word orange in it?
Yes, it will rewrite all requests to the /blocked.php script as long as "orange" is in the referer. The "Referer" header is what browsers typically include in a request letting the webserver know what page/site they were just at that linked to the resource that they're requesting. That means if there's a site called "orange.com" that has a page that links to one of your pages, and someone clicks on it, the referer will contain that orange.com page and the rules you have will block them.
You don't need the OR flag. Leaving it out works for me when the referer contains the word "orange". Just keep in mind that referers can be spoofed and it isn't a guarantee.

.htaccess redirect to subfolder, and remove it's name

I'm kind of noob in the world of web so my apologies... I tried many things found on SO and elsewhere, but I didn't manage to do what I want. And the Apache documentation is... well too much complete.
Basically what I want to do is redirect my domain to a subfolder. I found easy solutions for this (many different actually).
http://www.foo.com/
http://foo.com/
should redirect to /bar and appear as http://foo.com/
Using the following I got the expected result :
RewriteEngine on
Options +FollowSymLinks
RewriteCond %{HTTP_HOST} ^www\.foo.com$
RewriteRule ^/?$ "http\:\/\/foo.com" [R=301,L]
RewriteRule ^((?!bar/).*)$ bar/$1 [NC,L]
But I also want the subfolder as well as filenames not to appear when explicitly entered, i.e :
http://www.foo.com/index.html
http://foo.com/index.html
http://wwww.foo.com/bar
http://foo.com/bar
http://wwww.foo.com/bar/index.html
http://foo.com/bar/index.html
Should all appear as
http://foo.com/
Is this possible ?
Obviously using .htaccess, since I'm on a virtual host.
Thanks
As Felipe says, it's not really possible, because you lose information when you do that R=301 redirect: a hard redirect like this starts a whole new request, with no memory of the previous request.
Of course, there are ways to do similar things. The easiest is to put the original request in the query string (here's a good rundown on how mod_rewrite works with query strings). Sure, the query string does show up in the URL, but most modern browsers hide the query string in the address bar, so if your goal is aesthethics, then this method would be workable.
If you really don't want to show any of the original query in the URL, you might use cookies by employing the CO flag (here are some very good examples about cookie manipulation). At any rate, the information about the original request must somehow be passed in the hard redirect.
But anyhow, and most importantly, why would you want to do something like this? It's bound to confuse humans and robots alike. Great many pages behaved like this back when frames were fashionable, and it was pretty terrible (no bookmarking, no easy linking to content, Google results with the snippet "your browser cannot handle frames", no reloading, erratic back button, oh boy, those were the days).
Speaking of which, if your content is html, you may just use a plain old iframe to achieve the effect (but I'd sincerely advise against it).

htaccess rewrite question

I need to redirect incoming requests for a page to a subdirectory whilst keeping the URL displayed as originally typed.
This is to manage language pages easier.
For example, I want Spanish pages to be under www.mydomain.com/es. I want the URL displayed to remain www.mydomain.com/es.
But the actual page is held here - www.mydomain.com/international/es
This means I can keep my root folder tidy and have all the language pages in one directory. But I want it to be easy for language specific visitors to find thier page.
Can anyone point me in the right direction? I've had a go but to be honest I always manage to produce server errors and get in a mess.
Many thanks
TT
Provided you are on an apache server look up mod_rewrite.
Example for your .htaccess:
RewriteEngine on
RewriteRule ^es/([0-9a-zA-Z\/]*)$ /international/es/$1 [L]

Getting "mywebsite.org/" to resolve to "mywebsite.org/index.php"

At my work we have various web pages that, my boss feels, are being ranked lower than they should be because "mywebsite.org/category/" looks like a different URL to search engines than "mywebsite.org/category/index.php" does, even though they show the same file. I don't think it works this way but he's convinced. Maybe I'm wrong though. I have two questions:
How do i make it so that it will say "index.php" in the address bar of all subcategories?
Is this really how pagerank works?
Besides changing all the links everywhere, a simpler solution is to use a rewrite rule. Make sure it is a permanent redirect, or Google will keep using the old link (without index.php). How you do this exactly depends on your web server, but for Apache HTTPd it looks something like the example given below.
Yes. Or so I've heard. Very few people know for sure. But Google mentions this guideline (as "Be consistent"). Make sure to check out all of Google's Webmaster guidelines.
Apache config for rewrite rule:
# in the generic config
LoadModule rewrite_module modules/mod_rewrite.so
# in your virutal host
RewriteEngine On
# redirect everything that ends in a slash to the same, but with index.php added
RewriteRule ^(.*)/$ $1/index.php [R=301,L]
# or the other way around, as suggested
# RewriteRule ^(.*)/index.php$ $1/ [R=301,L]
Adding this code to the top of every page should also work:
<?php
if (substr($_SERVER['REQUEST_URI'], -1) == '/') {
$new_request_uri = $_SERVER['REQUEST_URI'].'index.php';
header('HTTP/1.1 301 Moved Permanently');
header('Location: '.$new_request_uri);
exit;
}
?>
You don't tell us if you're using straight PHP or some other framework, but for PHP, probably you just need to change all the links on your site to "mywebsite.org/category/index.php".
I think it's possible that this does affect your search engine rank. However, you would be better off using only "mywebsite.org/category" rather than adding "index.php" to each one.
Bottom line is that you need to make sure all your links in your website use one or the other. What actually gets shown in the address bar is unimportant.
A simple solution is to put in the <head> tag:
<link rel="canonical" href="http://mywebsite.org/category/" />
Then, no matter which page the search engine ends up on, it will know it is simply a different view of /category/
And for your second question--yes, it can affect your results, if Google thinks you are spamming. If it wasn't, they wouldn't have added support for rel="canonical". Although I wouldn't be surprised if they treat somedir/index.* the same as somedir/
I'm not sure if /category/ and /category/index.php are considered two urls for seo, but there is a good chance that it will effect them, one way or another. There is nothing wrong with making a quick change just to be sure.
A few thoughts:
URLs
Rather than adding /index.php, you will be better off making it so there is no index.php on any of them, since the keyword 'index' is probably not what you want.
You can make a script that will check if the URL of the current page ends in index.php and remove it, then forward to the resulting URL.
For example, on one of my sites, I require the 'www.' for my domain (www.domain.com and domain.com are considered two URLs for search purposes, though not always), so I have a script that checks each page and if there is no www., it ads it, and forwards.
if (APPLICATION_LIVE) {
if ( (strtolower($_SERVER["HTTP_HOST"]) != "www.domain.com") ) {
header("HTTP/1.1 301 Moved Permanently"); // Recognized by search engines and may count the link toward the correct URL...
header("Location: " . 'www.domain.com/'.$_SERVER["REQUEST_URI"] );
exit();
}
}
You could mode that to do what you need.
That way, if a crawler visits the wrong URL, it will be notified that it was replaced with the correct URL. If a person visits the wrong URL, they will be forwarded to the correct URL (most won't notice), and then if they copy the url from the browser to send someone or link to that page, they will end up linking to the correct url for that page.
LINKING URLS
They way other pages link to your pages is more important for seo. Make sure all your in-site links use the proper URL (without /index.php), and that if you have a 'link to this page' feature, it doesn't include the /index.php part. You can't control how everyone links to you, but you can take some control over it, like with the script in item 1.
URL ROUTING
You may also want to consider using some sort of framework or stand-alone URL rerouting scheme. It could make it so there were more keywords, etc.
See here for an example: http://docs.kohanaphp.com/general/routing
I agree with everyone who's saying to ditch the index.php. Please don't force your visitor to type index.php if not typing it could get them the same result.
You didn't say if you're on an IIS or Apache server.
IIS can be set to assume index.php is the default page so that http:// mywebsite.org/ will resolve correctly without including index.php.
I would say that if you want to include the default page and force your users to type the page name in the url, make the page name meaningful to a search engine and to your visitors.
Example:
http://mywebsite.org/teaching-web-scripting.php
is far more descriptive and beneficial for SEO rankings than just
http://mywebsite.org/index.php
Might want to take a look at robots.txt files? Not quite the best solution, but you should be able to implement something workable with them...

Resources