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.
Results 1 to 14 of 14
  1. #1
    New to the CF scene
    Join Date
    May 2009
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Trying to rewrite some URLs, confused.

    Code:
    Options +FollowSymLinks 
    RewriteEngine On 
    RewriteRule ^(.*?)/(.*?)/(.*?)/(.*?)/(.*)$ index.php?page=$1-$2-$3-$4-$5 
    RewriteRule ^(.*?)/(.*?)/(.*?)/(.*)$ index.php?page=$1-$2-$3-$4 
    RewriteRule ^(.*?)/(.*?)/(.*)$ index.php?page=$1-$2-$3 
    RewriteRule ^(.*?)/(.*)$ index.php?page=$1-$2 
    RewriteRule ^(.*)$ index.php?page=$1
    I'm trying to get some URLs to convert like follows

    http://www.domain.com/index.php?page=word1-word2-word3 to convert to http://www.domain.com/word1/word2/word3/

    With those current rules it just goes to what index.php outputs, rather than index.php?page=word1-word2-word3 . The same goes if I go up to word5, or down to word2.

    Although,

    http://www.domain.com/index.php?page=word1 WORKS, it will convert to http://www.domain.com/word1/ - it just won't do anything further on.

    Does anyone know what I need to do to make this work?

    Thanks for any help you can provide, my knowledge of this is very limited.

  • #2
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    from this:

    http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html

    see the "Ruleset Processing":

    http://httpd.apache.org/docs/2.0/mod...nternalRuleset

    and read about "flags":

    http://httpd.apache.org/docs/2.0/mod...l#rewriteflags

    try to solve your problem by adding the L flag to each rule.

    best regards

  • #3
    New to the CF scene
    Join Date
    May 2009
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I've tried addin [L] to each rule as follows:
    Code:
    Options +FollowSymLinks
    RewriteEngine On 
    RewriteRule ^(.*?)/(.*?)/(.*?)/(.*?)/(.*)$ index.php?page=$1-$2-$3-$4-$5 [L]
    RewriteRule ^(.*?)/(.*?)/(.*?)/(.*)$ index.php?page=$1-$2-$3-$4 [L]
    RewriteRule ^(.*?)/(.*?)/(.*)$ index.php?page=$1-$2-$3 [L]
    RewriteRule ^(.*?)/(.*)$ index.php?page=$1-$2 [L]
    RewriteRule ^(.*)$ index.php?page=$1 [L]
    With no success .

  • #4
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by samcroft View Post
    I've tried addin [L] to each rule as follows:
    Code:
    Options +FollowSymLinks
    RewriteEngine On 
    RewriteRule ^(.*?)/(.*?)/(.*?)/(.*?)/(.*)$ index.php?page=$1-$2-$3-$4-$5 [L]
    RewriteRule ^(.*?)/(.*?)/(.*?)/(.*)$ index.php?page=$1-$2-$3-$4 [L]
    RewriteRule ^(.*?)/(.*?)/(.*)$ index.php?page=$1-$2-$3 [L]
    RewriteRule ^(.*?)/(.*)$ index.php?page=$1-$2 [L]
    RewriteRule ^(.*)$ index.php?page=$1 [L]
    With no success .
    try this way:

    Code:
    Options +FollowSymLinks
    RewriteEngine On 
    RewriteRule ^(.*?)\/(.*)$ index.php?page=$1-$2 [L]
    RewriteRule ^(.*)$ index.php?page=$1 [L]
    best regards

  • #5
    New to the CF scene
    Join Date
    May 2009
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I've managed to get this working, seems like it was a problem within the index.php file rather than .htaccess in the end.

    ----

    In my scripts for all the image locations it is doing it as the new directory, /images

    so its trying to say the images are in /word1/word2/word3/images

    rather than /images

    This is probably since the file locations are like this:

    Code:
    <img src="images/top_shared.gif">
    Is there any way to make sure it does treat it in the right directory, rather than me having to replace them all with http://www.domain.com/images/image.gif ?

    ---

    Also, it no longer lets me browse directories which were there previously, which have contents in which I need to view, it just returns the index page .

  • #6
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    try to put on top before other rules:
    Code:
    RewriteRule ^images\/(.+)$ images/$1 [L]
    after first match redirection will stop because of L.

    best regards

  • #7
    New to the CF scene
    Join Date
    May 2009
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I've tried that with no success:

    Code:
    Options +FollowSymLinks
    RewriteEngine On
    RewriteRule ^images\/(.+)$ images/$1 [L]
    RewriteRule ^(.*?)\/(.*?)\/(.*?)\/(.*?)\/(.*)$ index.php?page=$1z$2z$3z$4z$5 [L]
    RewriteRule ^(.*?)\/(.*?)\/(.*?)\/(.*)$ index.php?page=$1z$2z$3z$4 [L]
    RewriteRule ^(.*?)\/(.*?)\/(.*)$ index.php?page=$1z$2z$3 [L]
    RewriteRule ^(.*?)\/(.*)$ index.php?page=$1z$2 [L]
    RewriteRule ^(.*)$ index.php?page=$1 [L]
    It is still coming up with the same wrong file path

  • #8
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by samcroft View Post
    I've tried that with no success:

    Code:
    Options +FollowSymLinks
    RewriteEngine On
    RewriteRule ^images\/(.+)$ images/$1 [L]
    RewriteRule ^(.*?)\/(.*?)\/(.*?)\/(.*?)\/(.*)$ index.php?page=$1z$2z$3z$4z$5 [L]
    RewriteRule ^(.*?)\/(.*?)\/(.*?)\/(.*)$ index.php?page=$1z$2z$3z$4 [L]
    RewriteRule ^(.*?)\/(.*?)\/(.*)$ index.php?page=$1z$2z$3 [L]
    RewriteRule ^(.*?)\/(.*)$ index.php?page=$1z$2 [L]
    RewriteRule ^(.*)$ index.php?page=$1 [L]
    It is still coming up with the same wrong file path
    can you post a link? also, take it step by step, comment all lines in htaccess and starting from top do change on the line untill work, then go to next line.

    something like this:
    Code:
    Options +FollowSymLinks
    RewriteEngine On
    RewriteRule ^images/(.+)$ images/$1 [L]
    #RewriteRule ^(.*?)\/(.*?)\/(.*?)\/(.*?)\/(.*)$ index.php?page=$1z$2z$3z$4z$5 [L]
    #RewriteRule ^(.*?)\/(.*?)\/(.*?)\/(.*)$ index.php?page=$1z$2z$3z$4 [L]
    #RewriteRule ^(.*?)\/(.*?)\/(.*)$ index.php?page=$1z$2z$3 [L]
    #RewriteRule ^(.*?)\/(.*)$ index.php?page=$1z$2 [L]
    RewriteRule ^(.*)$ index.php?page=$1 [L]
    remove slash, maybe this is the problem.

    best regards

  • #9
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,801
    Thanks
    160
    Thanked 2,216 Times in 2,203 Posts
    Blog Entries
    1
    This is probably since the file locations are like this:

    Code:
    <img src="images/top_shared.gif">
    Is there any way to make sure it does treat it in the right directory, rather than me having to replace them all with http://www.domain.com/images/image.gif ?
    Yes, make them like
    Code:
    <img src="/images/top_shared.gif">
    (The same absolute path technique can be used with files like css and javascript, to avoid messing their paths with the results of mod_rewrite )
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #10
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by abduraooft View Post
    Yes, make them like
    Code:
    <img src="/images/top_shared.gif">
    (The same absolute path technique can be used with files like css and javascript, to avoid messing their paths with the results of mod_rewrite )
    that means "to replace them all",

    best regards

  • #11
    New to the CF scene
    Join Date
    May 2009
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Hi everyone,

    Thanks for all of your help so far. I had to leave this problem for a while due to having to do some other things.

    The image fix worked great, another similar problem has cropped up though.

    I've got some folders which I want to get to on the site.

    One of the folders I want to get to is http://www.domain.com/blog/ which has a wordpress blog inside of it.

    When I try and load that URL, it just pulls up the site index page.

    I added the same sort of code which I did for images but it isn't working.

    My .htaccess at current:
    Code:
    Options +FollowSymLinks
    RewriteEngine On
    RewriteRule ^images\/(.+)$ images/$1 [L]
    RewriteRule ^blog\/(.+)$ blog/$1 [L]
    RewriteRule ^(.*?)\/(.*?)\/(.*?)\/(.*?)\/(.*)$ index.php?page=$1z$2z$3z$4z$5 [L]
    RewriteRule ^(.*?)\/(.*?)\/(.*?)\/(.*)$ index.php?page=$1z$2z$3z$4 [L]
    RewriteRule ^(.*?)\/(.*?)\/(.*)$ index.php?page=$1z$2z$3 [L]
    RewriteRule ^(.*?)\/(.*)$ index.php?page=$1z$2 [L]
    RewriteRule ^(.*)$ index.php?page=$1 [L]
    Any help you can provide would be great, Thanks.

  • #12
    Regular Coder
    Join Date
    Oct 2004
    Posts
    330
    Thanks
    0
    Thanked 13 Times in 13 Posts
    Relative paths can also be fixed with the HTML <base> element.

    Code:
    ^blog\/(.+)$
    does not match /blog/. Try
    Code:
    Options +FollowSymLinks
    
    RewriteEngine On
    
    # Ignore /blog and /images.
    RewriteRule ^(blog|images)(/.*)?$ - [L]
    
    RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ /index.php?page=$1z$2z$3z$4z$5 [L]
    RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$         /index.php?page=$1z$2z$3z$4    [L]
    RewriteRule ^([^/]+)/([^/]+)/([^/]+)/?$                 /index.php?page=$1z$2z$3       [L]
    RewriteRule ^([^/]+)/([^/]+)/?$                         /index.php?page=$1z$2          [L]
    RewriteRule ^([^/]+)/?$                                 /index.php?page=$1             [L]

  • Users who have thanked schleppel for this post:

    samcroft (06-14-2009)

  • #13
    New to the CF scene
    Join Date
    May 2009
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thanks, that worked great.

    Something which I've noticed about the new way it processes URLs is that even if there isn't a index.php?page=XXXXXXXXXXX, that it will still give the homepage.

    Is there any way it can be that if there is NOT a relevant index.php?page that it shows an not found error? I'm just thinking that this will make search engines like Google not too happy with content which is the same.

    Thanks,
    Sam

  • #14
    Regular Coder
    Join Date
    Oct 2004
    Posts
    330
    Thanks
    0
    Thanked 13 Times in 13 Posts
    Do you mean when someone accesses example.com/fake/page they see the homepage and not a 404 error? To fix that you will have to edit your PHP script as mod_rewrite does not know if a page exists or not. If/when you do, send a 404 header with the PHP header() function
    Code:
    header('Content-Type: text/html', true, 404);


  •  

    Posting Permissions

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