I want to make custom urls for my site for example I want url like
http://www.mysite.com/first-link-page/
http://www.mysite.com/second-link-page/
Here, first-link-page,second-link-page,… etc is not folder for each link. It is dynamically generated pages using .htaccess file. I used comman templet file to which I pass varibles(i.e. value like first-link-page for example) and based on that page is display. In .htaccess file I use following code
RewriteEngine on
RewriteRule ^([^/.]+)/$ mytemplet.php?parameter=$1 [QSA,L]
This works fine. But if in browser user typed
http://www.mysite.com/first-link-page //without slash at ending
http://www.mysite.com/second-link-page
It gives page not found error. I want .htaccess to automatically add slash at end so that my url works fine. How do I do that. Please Help.
Thanks in advance..
To make a single character optional in a regex, just put a question mark efter it.
That would make your rewriterule;
Note the question mark after the / you want to be optionally matched against your URL.