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

Thread: htaccess redirects for URLs with arguments

  1. #1
    Join Date
    Jun 2010
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default htaccess redirects for URLs with arguments

    Question about 301 redirect / modrewrite

    I know there are a lot of topics on this subject but so far I have not managed to create my needed redirect.


    here is my current URL : mysite.net/doc.php?title=john

    needs to redirect to : mysite.net/doc.php?renamed=john&id=3340

    so am adding 'id' and renaming the variable 'title'.

    does anyone know if this can actually be done ?

  2. #2
    Join Date
    Jun 2010
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by alankeys View Post
    Question about 301 redirect / modrewrite

    I know there are a lot of topics on this subject but so far I have not managed to create my needed redirect.


    here is my current URL : mysite.net/doc.php?title=john

    needs to redirect to : mysite.net/doc.php?renamed=john&id=3340

    so am adding 'id' and renaming the variable 'title'.

    does anyone know if this can actually be done ?



    Would appreciate any comments or advice on above... Thanks.

  3. #3
    Join Date
    Jun 2010
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Would appreciate any comments or advice on above... Thanks.

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Assuming you tried:

    Code:
    Redirect 301 /doc.php?title=john http://mysite.net/doc.php?renamed=john&id=3340
    ?
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. #5
    Join Date
    Jun 2010
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks John.

    URL Parameters are not allowed at all in 301 redirects to the best of my knowledge.

    The following has been suggested but I still cant make it work...

    PHP Code:
    RewriteEngine on 
    RewriteCond 
    %{QUERY_STRING} ^([^&]*&)*title=([^&]+)
    RewriteRule ^/stock-charts/doc.phphttp://www.mysite.co.uk/stock-charts/doc.php      [this part is unclear]    [L,R=301] 
    Its as close as I have got...

  6. #6
    Join Date
    Nov 2014
    Location
    On A Scottish Island
    Posts
    488
    Thanks
    0
    Thanked 62 Times in 58 Posts

  7. #7
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Perhaps a PHP redirect would be more applicable. Does your host support PHP?
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  8. #8
    Join Date
    Jun 2010
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    thnks for comments
    xtyx it doesnt work for URLs with parameters.
    jscheuer1 Have you any idea what the code would be ??

  9. #9
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    This appears to work, it would have to be the first thing on doc.php:

    PHP Code:
    <?php
    if(isset($_GET['title']) && $_GET['title'] === 'john'){
        
    header('Location: ./doc.php?renamed=john&id=3340');
        exit;
    }
    ?>
    Or:

    PHP Code:
    <?php
    if(isset($_GET['title']) && $_GET['title'] === 'john'){
        
    header("HTTP/1.1 301 Moved Permanently"); 
        
    header('Location: ./doc.php?renamed=john&id=3340');
        exit;
    }
    ?>
    Depending upon the exact reason you're doing this, you might want to be more specific, like eliminating the possibility of all other post and get values, and/or be more general by redirecting all title to renamed, and possibly having a lookup for what each name would have as id.
    Last edited by jscheuer1; 12-08-2016 at 05:37 PM. Reason: add info
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  10. #10
    Join Date
    Jun 2010
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    John

    Im going to look at these but 'id' is also to be fetched from the database. Im imagining that the code needs to also fetch 'id' that is related to 'title'.
    also would like to contain these in a separate file that resides with the applicable directory/.

Similar Threads

  1. Replies: 1
    Last Post: 01-02-2010, 10:59 PM
  2. .htaccess help to rewrite URLs
    By Beverleyh in forum Looking for such a script or service
    Replies: 3
    Last Post: 06-11-2009, 12:18 PM
  3. Resolved Tracking dynamic .HTACCESS redirects?
    By Spinethetic in forum PHP
    Replies: 1
    Last Post: 05-02-2009, 03:22 PM
  4. Resolved Help with passing arguments with AJAX
    By Schmoopy in forum JavaScript
    Replies: 2
    Last Post: 03-09-2009, 07:10 PM
  5. Using htaccess for permanent redirects
    By wkenny in forum Other
    Replies: 0
    Last Post: 01-29-2006, 11:34 PM

Bookmarks

Posting Permissions

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