Hi guys,

I'm trying to make my URLs clean using mod_rewrite module. I've read many articles and tutorials about it and it seems it's partly working...PARTLY...I don't know why, so I'd really appreciate if anyone could help 🙂

This is the URL of the page I'm talking about:

http://stanstuff.comoj.com

And this is the content of my .htaccess file:

Options +FollowSymlinks
RewriteEngine On
RewriteRule ([-])-([-])$ /?id=$1&page=$2 [L]

This works but only for my guestbook since all the other links of the main menu have only one variable in their URLs. If I add another line, like this:

RewriteRule ([/]*)$ /?id=$1 [L]

It stops working 🙁

Any help appreciated!

    If you provide some sample urls you can probably get help - it'll either be in teh regular expression itself, or in the [L] (last rule) flag that your problem lies, probably.

      well thats the resulting urls you want, I gather, but using mod rewrite to create cleaner urls means you have some sort of incoming scheme in mind.
      it might be something like:
      http://stanstuff.comoj.com/author/
      http://stanstuff.comoj.com/guestbook/1/
      or it might be
      http://stanstuff.comoj.com/author
      http://stanstuff.comoj.com/guestbook-1
      or even
      http://stanstuff.comoj.com/id/guestbook/page/1/
      I don't know.
      but this is the incoming urls that mod rewrite will turn into your query strings so the internal site works, so we'd need to know what you want the external urls to look like to figure out the mod rewrite that will turn it into the internal strings.

        I see what you're aiming at. I'll need more types of rewrite rules but at this point I say this:

        http://stanstuff.comoj.com/author/
        http://stanstuff.comoj.com/guestbook/1/

        And I just noticed one thing. When I click on http://stanstuff.comoj.com/guestbook/1/ it appears in the address bar. But then I want to click on another link like http://stanstuff.comoj.com/author/ for example but there's http://stanstuff.comoj.com/guestbook/author/ instead...can you fix this?

          try something like:

          RewriteEngine On
          RewriteRule ^([^/]*)/([^/]*)/$ /?id=$1&page=$2 [QSA]

            I added your code to my .htaccess file but it doesn't work. Error page (404) shows up. Other links work but the guestbook one doesn't... 🙁

              4 days later
              CoderDan;10918572 wrote:

              but this is the incoming urls that mod rewrite will turn into your query strings so the internal site works, so we'd need to know what you want the external urls to look like to figure out the mod rewrite that will turn it into the internal strings.

              Does this require a RewriteCond? I'm stuck on the same problem... I've got the internal site rewriting correctly, but how can the URL reflect the changes in the address bar?

              trying to change the site from/to and here's the mod rewrite so far...

              www.site.com/?id=3&mls=123456
              www.site.com/mls/123456.php

              Options +FollowSymLinks
              RewriteEngine On
              RewriteRule mls/([/]*).php$ /index.php?id=3&mls=$1 [L]
              RewriteCond %{HTTP_HOST} /index.php?id=3 [NC]
              RewriteRule index.php$ /mls/$1.php? [R=301,L]

              This first rewrite rule works fine alone, but when I add the second one to mimic that change the URL in the address bar, I get a 404 error. Any suggestions?

                Write a Reply...