Jump to content

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
https://forums.phpfreaks.com/topic/278965-not-understanding-mod_rewrite/
Share on other sites

This is my .htaccess file.

 

ErrorDocument 404 http://google.com // Google just to test it
RewriteEngine On
RewriteRule ^([a-z]+)/([a-z\-]+)$ /$1/$2.php [L]
#LoadModule rewrite_module modules/mod_rewrite.so #AddModule mod_rewrite.c
RewriteRule ^page/([0-9]{4})$ /index.php?page=$1 [L]

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>

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]

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.
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.