RSS Forums RSS
Please support our Linux Servers and Apache advertiser: Programming Forums

Apache mod_rewrite with Google Ads

Join Date: Feb 2002
Location: Lawn Guylen, NY
Posts: 11,073
Reputation: cscgal is just really nice cscgal is just really nice cscgal is just really nice cscgal is just really nice cscgal is just really nice 
Rep Power: 33
Solved Threads: 118
Admin
Staff Writer
cscgal's Avatar
cscgal cscgal is offline Offline
The Queen of DaniWeb

Apache mod_rewrite with Google Ads

  #1  
Jul 12th, 2003
As you can see, the main forum and topic pages on this site display Google Ads. These text-based ads spider the site they're on and display relevant links targeted to the content of the current page. This works perfectly for a page such as

http://www.techtalkforums.com/forums/viewforum.php?f=1 which is the Windows forum, for example.

However, recently to increase search engine placement (as search engines far prefer static pages to dynamic pages) I used mod_rewrite in the .htaccess file to make the .php files appear as if they're static .html files. (Information about mod_rewrite can be found here: http://httpd.apache.org/docs/mod/mod_rewrite.html )

This was done via the following code in the .htaccess file:

RewriteEngine on 
 
# RewriteRule ^f([0-9]+)t([0-9]+)r([0-9]+)s(.*).(.*)$ /forums/viewforum.php?f=$1&topicdays=$2&start=$3&sid=$4 [L]
RewriteRule ^f([0-9]+)t([0-9]+)r([0-9]+).(.*)$ /forums/viewforum.php?f=$1&topicdays=$2&start=$3 [L]
# RewriteRule ^f([0-9]+)r([0-9]+)s(.*).(.*)$ /forums/viewforum.php?f=$1&start=$2&sid=$3 [L]
RewriteRule ^f([0-9]+)r([0-9]+).(.*)$ /forums/viewforum.php?f=$1&start=$2 [L]
# RewriteRule ^f([0-9]+)s(.*).(.*)$ /forums/viewforum.php?f=$1&sid=$2 [L]
RewriteRule ^f([0-9]+).(.*)$ /forums/viewforum.php?f=$1 [L]
 
# RewriteRule ^t([0-9]+)p([0-9]+)(.*)r([0-9]+)s(.*).(.*)$ /forums/viewtopic.php?t=$1&postdays=$2&postorder=$3&start=$4&sid=$5 [L]
RewriteRule ^t([0-9]+)p([0-9]+)(.*)r([0-9]+).(.*)$ /forums/viewtopic.php?t=$1&postdays=$2&postorder=$3&start=$4 [L]
# RewriteRule ^t([0-9]+)r([0-9]+)s(.*).(.*)$ /forums/viewtopic.php?t=$1&start=$2&sid=$3 [L]
RewriteRule ^t([0-9]+)r([0-9]+).(.*)$ /forums/viewtopic.php?t=$1&start=$2 [L]
# RewriteRule ^t([0-9]+)s(.*).(.*)$ /forums/viewtopic.php?t=$1&sid=$2 [L]
RewriteRule ^t([0-9]+).(.*)$ /forums/viewtopic.php?t=$1 [L]
# RewriteRule ^p([0-9]+)s(.*).(.*)$ /forums/viewtopic.php?p=$1&sid=$2 [L]
RewriteRule ^p([0-9]+).(.*)$ /forums/viewtopic.php?p=$1 [L]
 
# RewriteRule ^c([0-9]+)s(.*).(.*)$ /forums/index.php?c=$1&sid=$2 [L]
RewriteRule ^c([0-9]+).(.*)$ /forums/forums.php?c=$1 [L]
# RewriteRule ^s(.*).(.*)$ /forums/index.php?sid=$1 [L]
RewriteRule ^index.html$ /forums/index.php [L]
RewriteRule ^forums.html$ /forums/forums.php [L]
 
# RewriteRule ^m([0-9]+)s(.*).(.*)$ /forums/profile.php?mode=viewprofile&u=$1&sid=$2 [L]
RewriteRule ^m([0-9]+).(.*)$ /forums/profile.php?mode=viewprofile&u=$1 [L]

The .htaccess file only involves the homepage, board index, forum views, and topic views pages, as these are the only important ones to be indexed by search engines such as google.

What this does, for example, is it creates .html aliases for .php files, in layman terms. For example, you can use http://www.techtalkforums.com/forums/f1.html as a URL. This html file runs the associated .php script http://www.techtalkforums.com/forums/viewforum.php?f=1. Then, it forwards the output of this .php page over to the .html file for displaying.

Now here's the problem. When using the real URLs such as http://www.techtalkforums.com/forums/viewforum.php?f=1 the Google ads displayed are entirely relevant. For example, if you're in the Windows forum, it'll display Microsoft info, Linux forum displays Linux links, etc etc.

However, when using the html aliases, all of the ads displayed on every page are related to general computing. They're the same ads that are usually displayed on the index.php (index.html) and forum.php (forum.html) pages.

It's not like the google ads can't recognize the HTML pages at all, because then the ads wouldn't be relevant at all. But instead, they're relevant but to my index/forum homepages. The only code related to these HTML pages is in the .htaccess file displayed above. Can anyone spot any code in there that might be a reason for this?

I earn money for each click to the Google ads, and I would hate to lose so much money only because relevant ads aren't being displayed when they should.

TIA!

P.S. The reason that some of the lines of the .htaccess file are hashed out (commented out) is because those deal with Site IDs, which I prefer not to incorporate into the URLs on TechTalk Forums, although the default IS to include them on the phpBB forum software (that is used here). Any ideas would be greatly appreciated!

One more thing that might help in solving this dilemma. The two lines which are commented out ...

# RewriteRule ^c([0-9]+)s(.*).(.*)$ /forums/index.php?c=$1&sid=$2 [L]
# RewriteRule ^s(.*).(.*)$ /forums/index.php?sid=$1 [L]

... actually produce a very undesired effect when uncommented. They prevent access to the search.php page! Even though none of the code is related to search.php in any way, trying to access search.php when these lines aren't commented will always redirect you back to the main index page regardless of where you are.

Perhaps if those could redirect you to the index page, then other lines I don't have commented can redirect googlebot (google's spider) to the index page? (and therefore reading the index page's meta tags and content instead of the appropriate page's).

ONCE AGAIN, TIA
Last edited by cscgal : Dec 8th, 2003 at 4:49 pm.
Dani the Computer Science Gal
AddThis Social Bookmark Button
Reply With Quote  
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 6:32 am.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC