Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    New Coder
    Join Date
    Dec 2006
    Posts
    57
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Need help with .htaccess file

    Hello!
    I need all links ending in a digit to get to http://mysite.com/test.php?/d/get/thelink,

    for example http://mysite.com/fsdfsf8 should get to http://mysite.com/test.php?/d/get/fsdfsf8.

    I also need al links not ending with a digit to get to http://mysite.com/test.php?/thelink

    for example http://mysite.com/hello to get to http://mysite.com/test.php?/hello and http://mysite.com/hello/no to get to http://mysite.com/test.php?/hello/no .

    I've tried several different combinations but I havn't been able to solve it... here is what I tested last:

    Code:
    RewriteEngine on
    RewriteBase /
    RewriteRule ([7-8]+) index.php?/files/get/$1 
    RewriteRule (.*) index.php?/$1
    What am I doing wrong? Thanks

  • #2
    Super Moderator
    Join Date
    Feb 2009
    Location
    England
    Posts
    539
    Thanks
    8
    Thanked 63 Times in 54 Posts
    RewriteRule (.*[0-9])$ index.php?/files/get/$1 [L]
    RewriteRule (.*) index.php?/$1

    That should do it. Note the [L] to stop it trying any more matches, and the $ to anchor the regex to the end of the url
    lamped.co.uk :: Design, Development & Hosting
    marcgray.co.uk :: Technical blog

  • Users who have thanked Lamped for this post:

    oskare100 (12-05-2010)

  • #3
    New Coder
    Join Date
    Dec 2006
    Posts
    57
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Okey, great, thanks

    Now I've gotten this far:

    Code:
    RewriteRule ^deletefile/(.*) test.php/test/delete/$1    [L]
    RewriteRule (.*[qQ]/?[a-zA-Z0-9\.\(\)=?\}\]\[\{-]*?)$ test.php?/test/get/$1  [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond $1 !^(index\.php|images|img|css|js|robots\.txt)
    RewriteRule (.*) test.php?/$1 [L]
    It works apart from one thing, any URL looking like this: http://mysite.com/go/view/sdfsdsdfsfQ gets to test.php/test/get/sdfsdsdfsfQ when it should go to test.php/go/view/sdfsdsdfsfQ.. It follows the first rule even though go doesn't end with a Q or q, just the last peace of the link.
    Last edited by oskare100; 12-05-2010 at 02:28 PM.

  • #4
    Super Moderator
    Join Date
    Feb 2009
    Location
    England
    Posts
    539
    Thanks
    8
    Thanked 63 Times in 54 Posts
    (.*[qQ]/?[a-zA-Z0-9\.\(\)=?\}\]\[\{-]*?)$

    is...

    Anything, ending with a q or Q, optional /, 0 or many (non-greedy) range of letters. I'm not sure why you modified the * with ? as it's anchored anyway. You need to make the / or final range of characters have something not optional. It does match "/go/view/sdfsdsdfsfQ". Maybe if you're more specific about what *exactly* you need it to do, I can help more.
    lamped.co.uk :: Design, Development & Hosting
    marcgray.co.uk :: Technical blog

  • #5
    New Coder
    Join Date
    Dec 2006
    Posts
    57
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Oh, ok, well, absolutely, I've never used the .htaccess file before so I 'm not sure about what exactly everything means. I found a guide and in an example they used ? so I tested that as well :P

    Code:
    RewriteRule ^(.*[qQ]/?[a-zA-Z0-9\.\(\)=?\}\]\[\{-]*?) test.php?/files/get/$1  [L]
    The script I'm working on is based on another script and has different so called member pages, all of those looks like this: http://mysite.com/XXXXXQ, http://mysite.com/XXXXXq, http://mysite.com/XXXXXQ/notimportant or http://mysite.com/XXXXXq/notimportant - all of those should get to for example http://mysite.com/test.php/test/get/XXXXXq or http://mysite.com/test.php/test/get/XXXXXq/notimportant.

    Code:
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond $1 !^(test\.php|images|img|css|js|robots\.txt)
    That code has something to do with the base script, don't know exactly what it does but if I remove that all the fixed links stop working.

    Code:
    RewriteRule (.*) test.php/$1 [L]
    Then from the base script there are links that looks like http://mysite.com/view/download/XXXXXq and http://mysite.com/view/download/XXXXXQ and those should get to http://mysite.com/test.php/view/download/XXXXXQ plus other fixed links as for example http://mysite.com/view that should get to http://mysite.com/test.php/view

    So I think I need to somehow limit the first rule to just apply when the link lools like http://mysite.com/XXXXXq or http://mysite.com/XXXXXq/somethnig but not apply when the link looks like http://mysite.com/something/XXXXXq or http://mysite.com/something/XXXXXq/test
    Last edited by oskare100; 12-05-2010 at 07:44 PM.

  • #6
    Super Moderator
    Join Date
    Feb 2009
    Location
    England
    Posts
    539
    Thanks
    8
    Thanked 63 Times in 54 Posts
    I find it's best to be quite specific, I'd try:

    Code:
    # For /XXXXQ or /XXXXq only, with optional trailing slash
    RewriteRule ^(.*[qQ]/?)$ /test.php.... [L]
    
    # For /XXXXQ/something or /XXXXq/something
    RewriteRule ^(.*[qQ]/.+)$ /test.php.... [L]
    # If you want that to not include any paths past "something", do:
    # RewriteRule ^(.*[qQ]/[^/]+/?)$ /test.php.... [L]
    # ... which won't work with XXXXq/something/more
    
    # Everything else
    RewriteRule ^(.*)$ /test.php....
    Replace .... with whatever page it's meant to be, frankly I got a bit confused
    Last edited by Lamped; 12-05-2010 at 10:48 PM. Reason: Added optional trailing slash to condition 2
    lamped.co.uk :: Design, Development & Hosting
    marcgray.co.uk :: Technical blog

  • #7
    New Coder
    Join Date
    Dec 2006
    Posts
    57
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Great, that seams to almost be the solution I'm very thankful for the help you have given and I'm starting to learn how these files work now However, I see now that I unfortunately gave you wrong information on how the second links looks like (really sorry for that)...

    This one:
    RewriteRule ^(.*[qQ]/[^/]+/?)$ ......$1

    I think doesn't take like
    http://mysite.com/XXXXXq/test/another

    which is exactly what I wrote, but I ment that it shouldn't take links like
    http://mysite.com/test/another/XXXXXq

    which are now taken by
    RewriteRule ^(.*[qQ]/?)$ .....$1

    So I need to somehow limit so the link only applies to the rules if it starts with XXXXXq (like http://mysite.com/XXXXXq or http://mysite.com/XXXXq/test), and not if XXXXXq is somewhere else in the link (like http://mysite.com/thisis/XXXXXq.

    Thanks!

  • #8
    Super Moderator
    Join Date
    Feb 2009
    Location
    England
    Posts
    539
    Thanks
    8
    Thanked 63 Times in 54 Posts
    Did you put the [L] after "RewriteRule ^(.*[qQ]/?)$ .....$1", and ensure it appears before other entries?
    lamped.co.uk :: Design, Development & Hosting
    marcgray.co.uk :: Technical blog

  • #9
    New Coder
    Join Date
    Dec 2006
    Posts
    57
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Yes, this is how the lines look like now:

    Code:
    RewriteRule ^(.*[qQ]/?)$  test.php?/test/get/$1     [L]
    RewriteRule ^(.*[qQ]/[^/]+/?)$  test.php?/test/get/$1   [L]
    RewriteRule ^(.*) index.php?/$1 [L]
    So links like http://mysite.com/test/test/XXXXQ should follow the third rule but now it seams like it follows the first or second rule... Have I missplaced anything? Thanks

  • #10
    Super Moderator
    Join Date
    Feb 2009
    Location
    England
    Posts
    539
    Thanks
    8
    Thanked 63 Times in 54 Posts
    For clarity, can you give a list in the following format:

    Destination: /index.php?/$1
    /urlexample
    /urlexample
    /urlexample

    Destination: /test.php?/test/get/$1
    /urlexample
    /urlexample
    /urlexample

    and any other destinations
    lamped.co.uk :: Design, Development & Hosting
    marcgray.co.uk :: Technical blog

  • #11
    New Coder
    Join Date
    Dec 2006
    Posts
    57
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Absolutely

    Destination: /index.php?/$1
    /anything/test/XXXXXq
    /anything/XXXXXQ

    Destination: /test.php?/test/get/$1
    /XXXXXq
    /XXXXXQ/anything
    /XXXXXq/anything/test

  • #12
    Super Moderator
    Join Date
    Feb 2009
    Location
    England
    Posts
    539
    Thanks
    8
    Thanked 63 Times in 54 Posts
    Code:
    # /XXXXQ/something
    RewriteRule ^(/[^/]*[Qq])/?$    /test.php?/test/get/$1 [L]
    RewriteRule ^(/[^/]*[Qq])/.+)/?$  /test.php?/test/get/$1 [L]
    
    # /something/XXXXQ
    RewriteRule ^(/.*/[^/]*[Qq])/?$    /index.php?/$1 [L]
    lamped.co.uk :: Design, Development & Hosting
    marcgray.co.uk :: Technical blog

  • #13
    New Coder
    Join Date
    Dec 2006
    Posts
    57
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Hmm.. this one:
    Code:
    RewriteRule ^(/[^/]*[Qq])/?$    /test.php?/test/get/$1 [L]
    does not work with
    /XXXXXQ or
    /XXXXxq/test

    And this one:
    Code:
    RewriteRule ^(/[^/]*[Qq])/.*)/?$  /test.php?/test/get/$1 [L]
    gives me

    Code:
    Internal Server Error
    
    The server encountered an internal error or misconfiguration and was unable to complete your request.
    
    Please contact the server administrator, webmaster and inform them of the time the error occurred, and anything you might have done that may have caused the error.
    
    More information about this error may be available in the server error log.
    
    Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.
    and if I remove the extra ) it doesn't give me Internal Server Error anymore but it doesn't do what it should anyway..

    Strange?
    Last edited by oskare100; 12-06-2010 at 06:45 PM.

  • #14
    Super Moderator
    Join Date
    Feb 2009
    Location
    England
    Posts
    539
    Thanks
    8
    Thanked 63 Times in 54 Posts
    Sorry about that extra )

    Code:
    # /XXXXQ
    RewriteRule ^(/[^/]*[Qq])/?$    /test.php?/test/get/$1 [L]
    
    # /XXXXQ/something
    RewriteRule ^(/[^/]*[Qq]/.+)/?$  /test.php?/test/get/$1 [L]
    
    # /something/XXXXQ
    RewriteRule ^(/.*/[^/]*[Qq])/?$    /index.php?/$1 [L]
    lamped.co.uk :: Design, Development & Hosting
    marcgray.co.uk :: Technical blog

  • Users who have thanked Lamped for this post:

    oskare100 (12-06-2010)

  • #15
    Super Moderator
    Join Date
    Feb 2009
    Location
    England
    Posts
    539
    Thanks
    8
    Thanked 63 Times in 54 Posts
    Also, I'm not an expert at Apache config. I am an expert at Regex (forgetting the odd extra parenthesis). I wonder what'll happen if you remove the RewriteCond and RewriteBase lines...
    lamped.co.uk :: Design, Development & Hosting
    marcgray.co.uk :: Technical blog


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •