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: [rentittoday] Removing "." from links

Hi rentittoday,

You might have some success using regular expressions.

You're probably using some now to insure that URLs have an http:// in the beginning of them.

Do a search for regular expressions or preg_replace on the forum or look up preg_replace on PHP.net.

Should be pretty straight forward.


Best,

Jerry Kornbluthb
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

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