Showing posts with label seo. Show all posts
Showing posts with label seo. Show all posts

Friday, 29 January 2016

Configure Url rewrite filter to make url seo friendly in struts 2

UrlRewrite Filter


Configuring Rules

1. type="forward"
This is the same as doing:
RequestDispatcher rq = request.getRequestDispatcher([to value]);
rq.forward(request, response);

- Use if you want to have friendly url's / RESTful urls / transparently forward request,
i.e. from /abc to /xyz without the user noticing it

- Also need to add :
 <dispatcher>FORWARD</dispatcher>
 <dispatcher>REQUEST</dispatcher>
entries for all filters to the <filter-mapping/> section of your apps
web.xml. By default filters are only run for REQUEST (i.e. from an external
http request) not for forwarded (or included for that matter) requests.

2. type="permanent-redirect" (301)
response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
response.setHeader("Location", [to value]);
(note, SC_MOVED_TEMPORARILY is HTTP status code 301)

3. type="temporary-redirect" (302)
response.setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY);
response.setHeader("Location", [to value]);
(note, SC_MOVED_TEMPORARILY is HTTP status code 302)

4. Adding Request Parameters to from
- Add it as &amp; E.g.:
<to>/world.jsp?country=$1&amp;city=$2</to>

Dynamically Reload Config
Change in web.xml
 <!-- set the amount of seconds the conf file will be checked for reload
    can be a valid integer (0 denotes check every time,
          empty/not set denotes no reload check) -->
    <init-param>
    <param-name>confReloadCheckInterval</param-name>
    <param-value>60</param-value>
    </init-param>

Debugging
Change in web.xml
 <!-- sets up log level (will be logged to context log)
    can be: TRACE, DEBUG, INFO (default), WARN, ERROR, FATAL, log4j, commons, sysout:{level} (ie, sysout:DEBUG)
          if you are having trouble using normal levels use sysout:DEBUG -->
    <init-param>
    <param-name>logLevel</param-name>
    <param-value>DEBUG</param-value>
    </init-param>

how to make drupal to work only for case sensitive url

Run below query on your drupal database
ALTER TABLE `url_alias` CHANGE `dst` `dst` VARCHAR( 128 ) CHARACTER SET latin1 COLLATE latin1_general_cs NOT NULL

Thursday, 28 January 2016

Hiding jsessionid parameter from Google using apache

If you're running a website on JBoss you may discover that Google has indexed your pages with a jsessionid query parameter in the links.
The Google crawl bot does not support cookies, therefore JBoss uses the jsessionid query parameter in order to maintain a session state without cookies. These query parameters can impact your Google rank and indexing efficiency as the same page can be indexed multiple times with different session ids, and dilute your ranking. Also, it leads to ugly links.
If you want to still be able to support non-cookie using users, but would like Google to see cleaner links, you can use Apache's mod_rewrite to modify the links for the Google bot only, leaving the normal functionality available to the rest of your users.
Assuming you have mod_rewrite enabled in your Apache instance, use this configuration in your apache config:
 # This should strip out jsessionids from google
 RewriteCond %{HTTP_USER_AGENT} (googlebot) [NC]
 ReWriteRule ^(.*);jsessionid=[A-Za-z0-9]+(.*)$ $1$2 [L,R=301]
This rule says for request where the user agent contains "googlebot" (with case insensitive matching), rewrite the URL without the jsessionid. It seems to work nicely.

Dashes vs. underscores whch is more SEO friendly

Dashes vs. underscores

I often get asked whether I’d recommend dashes or underscores for words in urls. For urls in Google, I would recommend using dashes. Why? To find out, let’s take a trip in the Google Time Machine. Set the dial for 1999, the year Matt first discovered Google. Matt was using, I dunno, maybe HotBot at that point? The curtain rises:
Matt: Hmm, this search for [FTP_BINARY] didn’t turn out the way I wanted. I got a couple scuzzy looking urls, and the other documents just have the words “FTP” and “BINARY” but the term “FTP_BINARY” doesn’t actually appear. (Note: Matt was a bit of a nerd, as you can tell.)
Some Random Person That I Don’t Remember: Have you tried Google?
Matt: What’s that?
SROTIDR: It’s a search engine written by nerds for nerds! They index numbers! Sometimes they even index punctuation, like “C++”. Try your underscore search there.
Matt: Okay, here goes. Whoa! They actually return pages with the literal string “FTP_BINARY”! That’s wicked cool! (Did I mention Matt was a nerd? Big-time nerd.)
SROTIDR: Yeah. The wild thing is that they wrote a paper about how they crawl the web and rank pages.
Matt: Well, now that’s just silly. I wonder why they didn’t keep it a secret? I bet those papers will make great reading for my information retrieval class.
I’ve stylized the conversation quite a bit, but I remember how impressed I was that Google indexed numbers and some punctuation (come to think of it, search engines have come a long way in five years). With underscores, Google’s programmer roots are showing. Lots of computer programming languages have stuff like _MAXINT, which may be different than MAXINT. So if you have a url like word1_word2, Google will only return that page if the user searches for word1_word2 (which almost never happens). If you have a url like word1-word2, that page can be returned for the searches word1, word2, and even “word1 word2″.
That’s why I would always choose dashes instead of underscores. To answer a common question, Google doesn’t algorithmically penalize for dashes in the url. Of course I can only speak for Google, not other search engines. And bear in mind that if your domain looks like www.buy-cheap-viagra-online-while-consolidating-your-debt-so-you-can-play-texas-holdem-while-watching-porn.com, that may still attract attention for other reasons. \":)\"

Example Usage

When http://d.com/the_top_apache_htaccess_article.html is requested by a browser or search engine, a Search-Engine Friendly 301 Redirect is sent telling the client that the correct location for the resource is at http://d.com/the-top-apache-htaccess-article.html

The Apache .htaccess underscore to hyphen conversion code


  RewriteRule ^([^_]*)_([^_]*)_([^_]*)_([^_]*)_([^_]*)_([^_]*)_(.*)$ $1-$2-$3-$4-$5-$6-$7 [L,R=301]
   RewriteRule ^([^_]*)_([^_]*)_([^_]*)_([^_]*)_([^_]*)_(.*)$ $1-$2-$3-$4-$5-$6 [L,R=301]
   RewriteRule ^([^_]*)_([^_]*)_([^_]*)_([^_]*)_(.*)$ $1-$2-$3-$4-$5 [L,R=301]
   RewriteRule ^([^_]*)_([^_]*)_([^_]*)_(.*)$ $1-$2-$3-$4 [L,R=301]
   RewriteRule ^([^_]*)_([^_]*)_(.*)$ $1-$2-$3 [L,R=301]
   RewriteRule ^([^_]*)_(.*)$ $1-$2 [L,R=301]

SEO issue when a webpage is accessiable using HTTP and HTTPS both

1 Problem Statement:If a site is severed on both HTTP and HTTPS . For same content we have http and https URL crawled by Google. 


Solutions: To Avoid duplicate content issue we should remove https URL from google index. To do the we will show different robots.txt content for HTTPS RewriteRule ^/robots.txt$ /robots_ssl.txt [PT,L] robots_ssl.txt content is given below User-agent: * Disallow: /