Jump to content

Not understanding mod_rewrite


JesseToxik

Recommended Posts

hey all,

 

In honesty I have looked at tutorials for creating "pretty links" and I can honestly say I do not understand how to use it.

I am using a navigation system that includes requested files using a URL like http://mysite.com?page=home. What I would like to do is make the links appear as http://mysite.com/page/home. How can I achieve this? I am not asking for the code to be written for me, just help in the right direction. Thanks

Link to comment
Share on other sites

RewriteRule ^page/([a-z0-9]+)$ /index.php?page=$1 [L]
That would match your /page/home example and translate it into /index.php?page=home. As far has making it look like /page/home in the browser, you just need to type in the URL that way. When you create your links you need to create them using the new friendly format, not the older query-string format.

 

<a href="/page/home">Go Home</a>
not

<a href="/index.php?page=home">Go Home</a>
Link to comment
Share on other sites

I tried adding what you suggested to my .htaccess  and it didnt work.

 

This is what I have.

 

ErrorDocument 404 http://mysite.com/404.php
RewriteEngine On
RewriteRule ^([a-z]+)/([a-z\-]+)$ /$1/$2.php [L]
#LoadModule rewrite_module modules/mod_rewrite.so #AddModule mod_rewrite.c
RewriteRule ^page/([a-z0-9]+)$ /index.php?page=$1 [L]
Link to comment
Share on other sites

Your first RewriteRule

RewriteRule ^([a-z]+)/([a-z\-]+)$ /$1/$2.php [L]
is going to match the /pages/home url first and send the request over to /pages/home.php. You need to either disable that rule or change their orders so the other one matches first.
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.