0

I've been searching, reading and spent the last 8 days trying to figure out converting dynamic links to "pretty" links.

I starting using .htaccess and rewrite rules.

I have this basic code in my .htaccess file:

Options +FollowSymlinks
RewriteEngine on

RewriteRule ^pc-download/([0-9]+)/([^/]*)\.html$ /cgi/pc_read\.pl\?show=$1 [NC]

This will internally redirect my links to the proper cgi file and returns the item.

The problem I'm having is for external links in search results. From what I've read & read & read, I should be using the RewriteCond %{THE_REQUEST} and then a RewriteRule.

Since I've changed how my links are structured, I don't know if what I'm looking to do is even possible.

In the RewriteRule for internal links, the first part is "hard coded" ie, I make pc-download part of the code. Next ([0-9]+) is the item ID which is the variable ?show=$1. Here is the tricky part, ([^/]*) is an asset name that is in the database but not in the original (old) url. In the internal links, I have it coded in the page so any links in my pages automatically get generated.

So, here is the way I would like the external link to go:

External link : www.xyz.com/cgi/script.pl?show=001 Landing page : www.xyz.com/pc-download/001/name-of-product.html

I looked at maybe using RewriteMap. I created a txt file with the " ID Name Of Product " inside but putting that in my .htaccess file kills the whole website without even having a RewriteRule active.

Am I just spinning my head for nothing or am I headed down the right path?

Alexander O'Mara
  • 58,688
  • 18
  • 163
  • 171
cooter
  • 1
  • You can not use the `RewriteMap` directive in htaccess, it can only be used in the central server configuration. If you have no access to that, you’re better off rewriting all those links to a script that figures out the correct target, and then redirects there. – CBroe Jan 11 '15 at 02:09
  • @CBroe, I do not have access to the central server so that option is out. As for a script, I'm not familiar with any scripting language well enough to know how difficult that task would be. At least I know now to stop going down the RewriteMap direction. – cooter Jan 11 '15 at 02:34
  • What do you use to display your website? – Sumurai8 Jan 11 '15 at 07:05
  • @Sumurai8, its a Perl script that reads a flat file database. At the time, I didn't have access to mySQL so I used a premade script. I know at some point I'll have to switch to a real database driven website but I'll have a lot to research and learn to switch to PHP & SQL. – cooter Jan 11 '15 at 14:54
  • I have no clue how to read your flat file database, so I can't help you much with creating the redirect in perl. [This question](http://stackoverflow.com/questions/3651694/how-can-i-redirect-the-client-from-one-cgi-page-to-another-using-perl) might be of help. If you do not have access to httpd.conf, then RewriteMap is no option. [My answer here](http://stackoverflow.com/questions/22576324/rewrite-urls-in-php/22578365#22578365) might be helpful for a php example. – Sumurai8 Jan 11 '15 at 18:26
  • Would it be possible to redirect an external link that goes to /cgi/pc_read.pl?show=$1 and send it to /cgi/pc_read.pl?show=$1&template=move? – cooter Jan 11 '15 at 19:38

1 Answers1

0

Wasn't able to figure out how to get the external link to go to a new page & get the new link structure/variable so I modified the .htaccess:

Options +FollowSymlinks
RewriteEngine on

RewriteRule ^pc-download/([0-9]+)/([^/]*)\.html$ /cgi/pc_read\.pl\?show=$1&mytemplate=Moved [NC]

Updated the old template page with a meta refresh:

<META http-equiv="refresh" content="0;URL=http://www.example.com/pc-download/[[gameid]]/[[assetname]].html">

This gets the 2 variables [[gameid]] & [[assetname]] from my database using the cgi script that runs my website and redirects to the proper URL structure.

Then, I created a new page that displays the old database information like before and all the URLs match up in the browser.

It isn't an ideal solution but it seems to work. I hope that the meta refresh lets the search engines know that is a permanent change/move and I'll be able to delete that step/page in a couple months.

cooter
  • 1