in .htaccess:

<ifModule mod_rewrite.c>
RewriteRule ^([a-zA-Z_]+)/?$ index.php?list=subcat&view=$1
RewriteRule ^([a-zA-Z_]+)/([a-zA-Z_]+)/?$ index.php?list=viewsubcat&view=$2&cat=$1
</ifModule>

That will match all lowercase/uppercase alpha characters with _ with an optional trailing slash and redirect them to ?list=subcat&view=(match). The second does the same, but two times, redirecting to ?list=viewsubcat&view=(match2)&cat=(match1)

I think. 🙂 Untested, but it should work with minimal tweaking.

    RewriteEngine On
    RewriteCond %{REQUEST_URI} !-f
    RewriteCond %{REQUEST_URI} !-d
    RewriteRule ^([A-z\s]+)/$ index.php?list=subcat&view=$1
    RewriteRule ^([A-z\s]+)/([A-z\s]+)/$ index.php?list=viewsubcat&view=$2&cat=$1

    EDIT: Ah, Horizon posted as I was typing. Note that my code sample is untested as well.

    EDIT2: Fixed some errors in the regexp.

      Thanks I will test this tonight.

        No luck, I tried both methods and nothing changed - I know I can use RewriteEngine as I have it on another directory program I was testing which worked.

        Any ideas?

        This is a sample of the other directory program I mentioned which can be previewed at: http://www.c4sites.co.uk/c4search_old

        RewriteEngine On
        
        RewriteRule ^(.*)/$ index.php?category=$1 [QSA,L]
        RewriteRule ^index([0-9]+).html$ index.php?category=&page=$1                        [QSA,L]
        RewriteRule ^index.html$ index.php?category=$1                                                                [QSA,L]
        RewriteRule ^(.*)/index.html$ index.php?category=$1                                                                [QSA,L]
        RewriteRule ^(.*)/index([0-9]+).html$ index.php?category=$1&page=$2        [QSA,L]
        
        RewriteRule ^([a-z]+)-listings.html$ listings.php?view=$1                                                [QSA,L]
        RewriteRule ^([a-z]+)-listings([0-9]+).html$ listings.php?view=$1&page=$2                [QSA,L]
        
        RewriteRule ^([^/]+)-l([0-9]+).html$ view-listing.php?title=$1&id=$2 [QSA,L]
        RewriteRule ^(.*)/(.*)-l([0-9]+).html$ view-listing.php?cat=$1&title=$2&id=$3 [QSA,L]
        

          Are they in seperate directories? Because if you have the .htaccess you've just posted in say, /site/.htaccess, and you have the one you're modifying now in /site/site2/.htacess, the rules from /site/.htaccess will be processed as well, I believe.

            no they are both different

            root/site1
            root/site2

              My approach has been to rewrite everything to a single page and have the php code figure out what the request is for, or if it should be 404 Not Found (or 403 in case of virtual directory listing denied). I think its the same approach that drupal uses.

                Horizon88 wrote:

                Is there an .htaccess in root/?

                There is a blank one but please bear in mind the directory script I download works perfectly however when I try create a similar system on my own directory it is not working.

                  Update.

                  Sorry guys the code works fine I did nt relaise I had to code the links to actualy use /cat/subcat/ - sorry!

                  I only have 1 problem left if the the category or subcat has a space (%20) it fails, any ideas?

                  RewriteCond %{REQUEST_URI} !-f
                  RewriteCond %{REQUEST_URI} !-d
                  RewriteRule ^([A-z\s]+)/$ index.php?list=subcat&view=$1
                  RewriteRule ^([A-z\s]+)/([A-z\s]+)/$ index.php?list=viewsubcat&view=$2&cat=$1
                  

                    You can try adding a space to the regex.
                    ([A-z \s]+)

                      Thanks Horizon but that gives me a 500 error, I could just str_replace everything with an underscore but I'd prefer not to.

                        Yeah, i've never worked with the \s that's in that regex - it could be something to do with that not playing well with the space character. We'll have to wait til somebody with a litle more regular expression know-how comes in 😛

                          Thanks for the help buts it seems your cant use a space so I have used an underscore.

                          This is the code I used for the .htaccess

                          RewriteEngine On
                          RewriteRule ^([a-zA-Z0-9_]+)/?$ index.php?list=subcat&view=$1
                          RewriteRule ^([a-zA-Z0-9_]+)/([a-zA-Z0-9_]+)/?$ index.php?list=viewsubcat&view=$2&cat=$1
                          
                            Write a Reply...