Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

How do I set up an htaccess redirect to Google Books

Posted on 2010-09-23
7
538 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
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

If your site has a few sections that need to be secure when data is transmitted between the server and local computer, such as a /order/ section for ordering or /customer/ which contains customer data, etc it would of course be recommended to secure…
I've written instructions for one router type, but this principle may be useful for others of the same brand and even other brands of router. Problem: I had an issue especially with mobile devices that refused to use DNS information supplied via…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

807 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