Announcement

Collapse
No announcement yet.

.htaccess rewrite rule question

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • .htaccess rewrite rule question

    Hi,
    I've set up a rewrite rule that strips out the .php and adds a forward slash -

    Code:
    AddType application/octet-stream .csv
    Options +FollowSymlinks
    RewriteEngine on 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteCond %{REQUEST_FILENAME}\.php -f 
    RewriteRule ^(.*)/$ $1.php
    it works fine, but now I've set up another rewrite rule to rewrite /categories.php?cat=venues
    to
    /categories/venues/

    Code:
    RewriteRule ^categories/(.*)/$ categories.php?cat=$1
    on categories.php, if I echo out $_GET['cat'], I get this -
    venues.php/venues
    When I was expecting just 'venues', I worked out that it was the first rule that was affecting the output, if I disable
    Code:
    RewriteRule ^(.*)/$ $1.php
    I get 'venues' as expected.

    How can I adjust the rules so that both work as I'd like?
    Thanks

  • #2
    so here is a question, why worry about taking off .php in the url? I say this as you can write your url anyway you like. So if you wrote

    site.com/categories/12

    and you have

    RewriteRule ^categories/(.*)/$ categories.php?cat=$1

    in .htaccess, it will still load categories.php. Then you can scrap that whole removal of .php. I made a function for some other scripts that creates the url. But I was using category names as well so they never had a .php file associated with them. As long a syou output the correct .php file it should all work.
    Have a Script or Snippet you want to share?

    WWW Standards: HTML 4.01,
    HTML 5, CSS2.1, CSS3, XHTML 1.0
    PHP Standards: PHP Standards

    Comment


    • #3
      Thanks Scoutt, I'll give it a go.
      All a bit voodoo to me!

      Comment


      • #4
        I removed the line -
        Code:
        RewriteRule ^(.*)/$ $1.php
        from .htaccess, and now my other links don't work. e.g
        site.com/contact/
        which should point to site.com/contact.php
        Last edited by Reiss; 11-17-2012, 02:44 PM.

        Comment


        • #5
          you would have to add the same for contact as you did for categories.
          Code:
          RewriteRule ^contact/$ contact.php
          just from the top of my head. There maybe a different, easier way.
          Have a Script or Snippet you want to share?

          WWW Standards: HTML 4.01,
          HTML 5, CSS2.1, CSS3, XHTML 1.0
          PHP Standards: PHP Standards

          Comment


          • #6
            thanks Scoutt,
            Don't mind adding each page as there's not too many, just as long as it all works.

            Comment

            Working...
            X