Removing "." from links

6 posts by 3 authors in: Forums > CMS Builder
Last Post: September 29, 2010   (RSS)

Hey Guys!
Some of our listings require a "." in the name of the listing.
For example:
"Cinema Camera Accesories Rental - Nikon 18mm f/3.5 Lens" is the name of our item so when we set the link with
<?php echo $record['_link'] ?>
It returns with a url that has a "." in it and browsers do not accept this.

We have tested it by manually removing the "." from the url and it displays the details page of the correct listing just fine.
Is there a way to be able to keep everything how we have it now but to strip the "."s out of the url link created?

Thanks!
Jason Glass

Re: [gkornbluth] Removing "." from links

By Chris - September 27, 2010

Hi rentittoday,

I'm not sure what the problem is here. I created a record with a title of "Cinema Camera Accesories Rental - Nikon 18mm f/3.5 Lens" and it worked fine as a '_link' in my FF, IE, and Chrome.

Can you show me an example of a page where a browser won't accept your _link? Also, what browser are you using?

Can you show me the PHP source code you're currently using to output your _links?
All the best,
Chris

Re: [chris] Removing "." from links

I am using Firefox.

Here is the code for the link
<a href="<?php echo $record['_link'] ?>"><strong><?php echo $record['name'] ?></strong></a>

I did not think of it at first but we use an .htaccess file to mask the urls here, which could be the issue:
RewriteCond %{QUERY_STRING} (.*)
RewriteRule ^viewers/broadcast_equipment_rentals_details\.php$ /broadcast-video-rentals/%1? [NC,R=301]
RewriteRule ^broadcast-video-rentals/([^/.]+)/?$ /viewers/broadcast_equipment_rentals_details.php?$1 [NC,L]


When you click on the link produced from the code below and rewritten by .htaccess it gives us the url below and a completely blank page. If I remove the period from the url everything pops up just fine:
http://www.rentittoday.com/broadcast-video-rentals/Cinema-Camera-Accesories-Rental---Nikon-18mm-f-3.5-Lens-157
Jason Glass

Re: [rentittoday] Removing "." from links

By Chris - September 27, 2010

Hi rentittoday,

I'm thinking it's that last rewrite rule there that's bungling things up. I imagine you could just remove the . from [^/.]+ in your rewrite rule, but if that doesn't work for some reason, the simplest thing to do would be to get rid of dots in your _link, as Jerry suggested.

Since you don't have any necessary dots in your _link (e.g. ".php") you can use a very simple regexp to change all dots into something else:

<a href="<?php echo preg_replace('/\./', '-', $record['_link']) ?>"><strong><?php echo $record['name'] ?></strong></a>

Does that help? Please let me know if you have any questions.
All the best,
Chris

Re: [chris] Removing "." from links

Thank for the suggestions.

I first tried your "preg_replace" and it created some crazy link urls, where it added an extra "/viewers" and the .htaccess seemed to be doing nothing. So, I then removed the preg_replace and took out the "." in the rewrite rule in .htaccess and everything works perfectly![:)]

Thanks again for your help!

Lauren
Jason Glass