Submit Your Article Forum Rules

Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: .htaccess, 301 Redirect Dynamic URL To Another Dynamic URL

  1. #1
    WebProWorld MVP morestar's Avatar
    Join Date
    Jun 2007
    Location
    Toronto, Ontario
    Posts
    4,163

    .htaccess, 301 Redirect Dynamic URL To Another Dynamic URL

    I've tried and tried...for some time now too...

    I need this: -thesite.com/?L=users.profile&id=4424 (this ID is variable so I'm using it as an example)
    To this: -thesite.com/?L=this-user.profile&id=4424

    I've replaced the http etc with a - so there are no links created in this post.

    PLEASE!
    Last edited by morestar; 04-05-2012 at 02:52 PM.

  2. #2
    Administrator weegillis's Avatar
    Join Date
    Oct 2003
    Posts
    5,784
    Looks like what you might need to do is create a Mod_Rewrite, rather than a redirect.

  3. #3
    WebProWorld MVP morestar's Avatar
    Join Date
    Jun 2007
    Location
    Toronto, Ontario
    Posts
    4,163
    I have no idea, really I don't but I do know that the search engines need to know it's a permanent move...It's honestly been years since I could find a solution for this.

  4. #4
    Administrator weegillis's Avatar
    Join Date
    Oct 2003
    Posts
    5,784
    Just throwing this one out here...
    Code:
    .htaccess
    
    RewriteEngine on
    RewriteCond %{QUERY_STRING} ^L=users.profile$1
    RewriteRule ^(.*)$ http://www.example.com/?L=this-user.profile$1 [L,R=301]
    It will end up being something along these lines, I expect.

  5. #5
    WebProWorld MVP morestar's Avatar
    Join Date
    Jun 2007
    Location
    Toronto, Ontario
    Posts
    4,163
    Sorry weegilis. That didn't work either. I have a lot of other 301s in the file for other pages and so forth but for some reason this just never wants to work. I've tried 301 redirect generators all day - still nothing.

    Maybe this will help:

    The users.profile part is: users = a directory and profile would be a file within that directory.

    I did create a duplicate of the above something like this-user for the directory and kept the profile file the same.

    The site works with this-user when navigating to it but that's not, it won't redirect...so weird...thanks though for your help weegilis...

  6. #6
    Administrator weegillis's Avatar
    Join Date
    Oct 2003
    Posts
    5,784
    What if 'profiles' was just another parameter: &D=profiles&&c. Then you could shorten the rewrite condition and rule to just "L=users$1" and "L=this-user$1" without the dots.

  7. #7
    WebProWorld MVP morestar's Avatar
    Join Date
    Jun 2007
    Location
    Toronto, Ontario
    Posts
    4,163
    OK I got this far:

    RewriteCond %{QUERY_STRING} ^L=[a-z]
    RewriteRule ^(.*)$ http://www.domain.com/?L=this-user.profile&id=$1 [L,R=301]

    [a-z] matches any character between a and z an so the end result URL that's now (finally some movement here) coming up is the following:

    http://www.domain.com/?L=this-user.profile&id=

    I tried this to get the ID to display an id:

    RewriteCond %{QUERY_STRING} ^L=[a-z]&id=$1
    RewriteRule ^(.*)$ http://www.domain.com/?L=this-user.profile&id=$1 [L,R=301]

    And the end result was nothing changed in the URL, the same old URL is displaying.

    So all I need to know how to do now is get that ID...

  8. #8
    WebProWorld MVP morestar's Avatar
    Join Date
    Jun 2007
    Location
    Toronto, Ontario
    Posts
    4,163
    This is the last I got...the previous example would redirect anything after L and I actually needed it to be an exact match:

    RewriteCond %{QUERY_STRING} ^L=users.*&id=$1
    RewriteRule ^(.*)$ http://www.domain.com/?L=this-user.profile&id=$1 [L,R=301]

    But this is doing nothing. If I write:

    RewriteCond %{QUERY_STRING} ^L=users.*
    RewriteRule ^(.*)$ http://www.domain.com/?L=this-user.profile&id=$1 [L,R=301]

    I get:

    http://www.domain.com/?L=this-user.profile&id=

    No good...I need to catch that variable...

  9. #9
    Administrator weegillis's Avatar
    Join Date
    Oct 2003
    Posts
    5,784
    Without going into it the way you have, I am dumbfounded as to what suggest.

    The * content is not copied into the wildcard $1 placeholder, perhaps? Seems you would need the wildcard in both condition and rule. Is there is a way to do it with two wildcards, maybe?

  10. #10
    WebProWorld MVP morestar's Avatar
    Join Date
    Jun 2007
    Location
    Toronto, Ontario
    Posts
    4,163
    OK weegilis, I got some help from another forum, I had to make a small edit but now it FINALLY works! It's been years!

    This is what I have:

    Code:
    RewriteCond %{QUERY_STRING} L=users.profile
    RewriteCond %{QUERY_STRING} id=(.*)
    RewriteRule ^(.*)$ http://www.domain.com/$1?L=this-user.profile&id=%1 [L,R=301]
    Which gives me http://www.domain.com/?L=this-user.profile&id=[any ID number]



    Now as you mentioned in your last post (I believe) this shouldn't work or it's not really the right way?

Posting Permissions

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