PHP Classes

Optional forward slash ("/") at the end of URLs?

Recommend this page to a friend!

      Url Rewriter  >  All threads  >  Optional forward slash ("/") at the...  >  (Un) Subscribe thread alerts  
Subject:Optional forward slash ("/") at the...
Summary:Optional forward slash ("/") at the end of URLs?
Messages:2
Author:Adam Mustill
Date:2008-12-12 16:29:08
Update:2012-06-01 12:04:12
 

  1. Optional forward slash ("/") at the...   Reply   Report abuse  
Picture of Adam Mustill Adam Mustill - 2008-12-12 16:29:08
I am looking to use this great class on an upcoming project of mine, but currently one issue I am having is preventing me from doing so.

I want my URLs like this: /product/product-name-1

But I also want them accessible via: /product/product-name-1/


If I add a URL rule using $url->add_rule("index.php", "/product/[name]-[id]/"); it is only accessible with the URL /product/product-name-1/. The URL /product/product-name-1 returns the error "Notice: Undefined offset: 2 in C:\xampp\htdocs\url_rewriter.php on line 90".

If I add a URL rule using $url->add_rule("index.php", "/product/[name]-[id]"); then it is accessible via the URL /product/product-name-1, but a blank page appears if I try and access it via /product/product-name-1/.

If I add a URL rule using $url->add_rule("index.php", "/product/[name]-[id]{/}"); then I receive various errors and the page is not accessible via any URL. I had hoped that the {} condition would let me access the page with or without the forward slash, such as in the example provided - $url->add_rule("index.php","/{index.[ext]}" );

I have found if I create two rules - one with the forward slash and one without - then it works, but I don't wish to create two rules for every URL.


Is there anyway to implement optional forward slashes at the end of URLs? Any information would be greatly appreciated.


Regards,

Adam

  2. Re: Optional forward slash ("/") at the...   Reply   Report abuse  
Picture of Roberto Xyz Roberto Xyz - 2012-06-01 12:04:12 - In reply to message 1 from Adam Mustill
Hi Adam, did you resolved your problem? If so, can you share the solution?

Thanks :)