Jump to content

URL Rewriting Questions..... Please Help !!!


dnmmx

Recommended Posts

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

Link to comment
Share on other sites

  • 3 weeks later...

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

 

Link to comment
Share on other sites

  • 1 month later...

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.