Jump to content

Recommended Posts

Hi, I am trying to create bautyful links using mod_rewrite, i'm not experienced in php.

 

My goal is to rewrite www.page.com/?example to www.page.com/example/

 

and www.page.com/?example=1 to www.page.com/example/1/

 

Can someone please help me with this? I tried:

RewriteRule ^([^.])$ /$1.php

and

RewriteRule ^([^/=&]+)[/=&]?$ ?$1 [L]

 

But I just can't get it right

Link to comment
https://forums.phpfreaks.com/topic/211842-help-with-rewriting/
Share on other sites

You have the concept flipped on it's head. You don't rewrite www.page.com/?example to www.page.com/example/ you actually rewrite the opposite of that. Therefore you need to make all links on your page appear like the second version, and you need to make the mod_rewrite rules match the second version. So for example your rule might be...

 

RewriteRule ^example/([0-9]+)/? /?example=$1

 

Your first rule rewrites requests for pages that don't have a file extension and adds .php to them and your second uses some code that irrelevant, but is close to being another method that will work for you.

Link to comment
https://forums.phpfreaks.com/topic/211842-help-with-rewriting/#findComment-1104313
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.