Solved

How do I set up an htaccess redirect to Google Books

Posted on 2010-09-23
7
535 Views
Last Modified: 2012-05-10
I'd like to set up an automated link shortener for Google Books that uses the GB id and redirects off a short domain (the below is a test domain), so that, for example:

http://gbook.comze.com/Im4JAAAAQAAJ

redirects to

http://www.google.com/books?id=Im4JAAAAQAAJ

Attached is my htaccess. It's not working. What am I doing wrong?

Thanks,

Nathan
Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^gbook.comze.com?$ [nc]
rewriterule ^(.*)$ http://http://www.google.com/books?id=$1 [r=301,nc]

Open in new window

0
Comment
Question by:nbierm65
  • 5
  • 2
7 Comments
 
LVL 26

Expert Comment

by:jar3817
ID: 33744961
Try adding "RewriteBase /" in between lines 2 and 3.

I'm assuming this file is named correctly (.htaccess) with the dot in front? And the file is located in the top of your document root? Is this your own server or hosted somewhere? Do you have the "AllowOverride AuthConfig" option set for your document root directory?
0
 

Author Comment

by:nbierm65
ID: 33745185
That didn't do it. It's named correctly (with the dot in front and htaccess as the file extension), in the top root. I added 'AllowOverride AuthConfig.' It's on a free server elsewhere (from 000webhost.com, which I use for live testing). Maybe it's a restriction of that host; I can try a different one...
AllowOverride AuthConfig

Options +FollowSymlinks
RewriteEngine on
RewriteBase /
rewritecond %{http_host} ^gbook.comze.com?$ [nc]
rewriterule ^(.*)$ http://http://www.google.com/books?id=$1 [r=301,nc]

Open in new window

0
 

Author Comment

by:nbierm65
ID: 33745217
The strange thing to me is I have another auto-shortener set up and working on the same host (different domains), with this code. It's WordPress, which might mean something. But take a look:
Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^cicw.ws?$ [nc]
rewriterule ^(.*)$ http://www.worshipsymposium.org/archive/?p=$1 [r=301,nc]

# force no-www
RewriteCond %{HTTP_HOST} !^cicw.ws$ [NC]
RewriteRule ^(.*)$ http://cicw.ws/$1 [L,R=301]

Open in new window

0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 26

Expert Comment

by:jar3817
ID: 33745241
The allowoveride is what tells apache to use the .htaccess file, so that goes in the main config, not in the htaccess itself. If it's a hosted account, I'm sure htaccess is setup on it. Perhaps this is something you have to enable on the domain? Did you check their control panel to see if there is such an option? Do you have access to any error logs (usually through their control panel), it might shed some light on the problem.
0
 

Author Comment

by:nbierm65
ID: 33745258
OK I'll check, thanks. Again, the weird thing (re my comment above) is that it's working on a different site at this same host without any extra configuration. But I'll see if there's something I can tweak..
0
 

Author Comment

by:nbierm65
ID: 33783911
OK, I'm wondering if the issue is that the Google Books link is dynamic, ending with '?id= ' -- should I do something like this? (via bit.ly/dqO3Jm)



RewriteEngine on 
RewriteCond %{QUERY_STRING} ^id=13$
RewriteRule ^/page.php$ http://www.example.com/newname.htm? [L,R=301]

Open in new window

0
 

Accepted Solution

by:
nbierm65 earned 0 total points
ID: 33788868
ah, it was just a double 'http://' in the code; no one caught it! Attached is the working code.
Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^example.com?$ [nc]
rewriterule ^(.*)$ http://www.google.com/books?id=$1 [r=301,nc]

Open in new window

0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Over the last year I have answered a couple of basic URL rewriting questions several times so I thought I might as well have a stab at: explaining the basics, providing a few useful links and consolidating some of the most common queries into a sing…
Occasionally you run into the website or two that will not resolve properly using your own DNS servers.  Some people simply set up global forwarders for their DNS server.  I don’t recommend doing this because it can cause problems resolving addresse…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question