dnmmx Posted April 2, 2007 Share Posted April 2, 2007 Hi all PHP Geeks, I want to enable URL-Rewriting in My Application Actually I m a newbie for PHP. I want to setup URL-Rewriting in a way that If I write http://www.site.com/page then it should become http://www.site.com/page/ i.e. it should add the slash at the end automatically. and this should be happen for Every page. and this should redirected to http://www.site.com/page.php Please not that I m not having Domain at root, so the RewriteBase would not be / I m having Access to the 2nd Directory in Hierarchy. i.e. /MyDir My Whole site is Contained within that Dir. Itself. so the RewriteBase would be /MyDir .............Right ?? One More thing if I am Having .htaccess file at the root level and not in my directory /MyDir does it make any diff. in writing the RewriteRule ?? As u can see I don't have any querystrings in URL, but I just want to make the URLs CLEAN and easily Memorable. Second, I have directory structure in my site so my URL can be like, http://www.site.com/directory/folder/page/ this should be redirected to the page http://www.site.com/directory/folder/page.php I hope I make myself clear I have tried alot but I don't have enough knowledge of RegEx, So can't do that properly. Hope I'll find the Answer from Here. Please Help me in writing appropriate Snippets in .htaccess file Thanks in Advance Quote Link to comment Share on other sites More sharing options...
shaymol Posted April 19, 2007 Share Posted April 19, 2007 Hi mates Apache mor rewriterule has the following structure RewriteRule pattern substitution [flags] In your first rule you specified that you want to redirect http://www.site.com/page to http://www.site.com/page.php and showing http://www.site.com/page/ in the address bar. According to the RewriteRule structure both of the task is not possible . Say for example RewriteRule ^([A-Za-z0-9-]+)$ /$1.php [QSA,L] By using the above rule if you type http://www.site.com/page it redirects you to the http://www.site.com/page.php but still show the http://www.site.com/page in the address bar I think the above code will help you Thanks ShaymoL Quote Link to comment Share on other sites More sharing options...
Guest Posted June 9, 2007 Share Posted June 9, 2007 I am trying this but when i go to the index page it tries to rewrite me. i added this but no such luck RewriteCond %{REQUEST_URI} !/index.* [NC,OR] any suggestions? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.