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 10 of 10
  1. #1
    New Coder
    Join Date
    Jul 2011
    Posts
    52
    Thanks
    4
    Thanked 0 Times in 0 Posts

    301 Redirection from old article to the new

    Hello all.
    My system based like that:
    http://www.url.com/1(the id)/article_name
    Whenever I change the article name, the url changes to:
    http://www.url.com/1/article_new_name
    In addition, I can access the article no matter what the name is, like that:
    http://www.url.com/1/bfdgfdgdf
    It will enter the same article as above.
    My problem: I'm trying to do: 301 redirection to all pages that are NOT the original url(the real name of the article) and the article will be accessible only in one, original url - even after I change the article name it will redirect the old url to the new one (301 redircetion).
    How I can do that?

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    These have nothing to do with PHP. PHP does not (generally) handle the input types or directory levels for any type of control within PHP; it only cares about a querystring. Assuming that you don't have an actual directory structure that creates a new directory and index for each article, this will be an apache configuration issue for an htaccess file using mod_rewrite.

  • #3
    New Coder
    Join Date
    Jul 2011
    Posts
    52
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Fou-Lu View Post
    These have nothing to do with PHP. PHP does not (generally) handle the input types or directory levels for any type of control within PHP; it only cares about a querystring. Assuming that you don't have an actual directory structure that creates a new directory and index for each article, this will be an apache configuration issue for an htaccess file using mod_rewrite.
    Ok, so you just explained about my problem - how the hell i fix it?

  • #4
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,304
    Thanks
    57
    Thanked 525 Times in 512 Posts
    Blog Entries
    5
    Post in the apache forum
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #5
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    Quote Originally Posted by tangoforce View Post
    Post in the apache forum
    Or just wait for the thread to get moved.


    Fou-Lu is right you need to use an htaccess file and mod_rewrite to accomplish that. Have you ever used regular expressions before?
    OracleGuy

  • #6
    New Coder
    Join Date
    Jul 2011
    Posts
    52
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by oracleguy View Post
    Or just wait for the thread to get moved.


    Fou-Lu is right you need to use an htaccess file and mod_rewrite to accomplish that. Have you ever used regular expressions before?
    Yeah I used it to make a SEO-FRIENDLY url like that url i gave above, but how I make that users will be able to access the url only from the originial one, because if users write: http://www.url.com/1/bfdgfdgdf they will access article id 1, and if they write: http://www.url.com/1/RealArticleName it will access article id 1 too. I want to redirect all the url's that are not RealArticleName to the RealArticleName URL.
    Got it?

  • #7
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    How are you going to determine what the 'real' article name is? The only requirement you have is a matching article id; there really isn't a way to determine what the title should be or whether its right or wrong.
    You should choose either the id or the title, and issue a 404 when the correct isn't found. The description indicates that the article title can change, which means you should be using the id as the means to identify it, and not the title.

  • #8
    New Coder
    Join Date
    Jul 2011
    Posts
    52
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Fou-Lu View Post
    How are you going to determine what the 'real' article name is? The only requirement you have is a matching article id; there really isn't a way to determine what the title should be or whether its right or wrong.
    You should choose either the id or the title, and issue a 404 when the correct isn't found. The description indicates that the article title can change, which means you should be using the id as the means to identify it, and not the title.
    Yeah I'm using the ID to identify it, but I want people to access the article only from the 'real' article name - How to determine it? from the database... everything is stored. I don't want to use the article name to identify it, I just want the article name to be the REAL one and if someone will write "ASDD" instead of the title it will redirect him to the REAL article name.

  • #9
    New Coder
    Join Date
    Jul 2011
    Posts
    52
    Thanks
    4
    Thanked 0 Times in 0 Posts
    2 days passed, any help?

  • #10
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    You don't.
    If I supply it with a valid id and any other type of querystring variable that's not handled, it is ignored. There is no way for you to determine what title is valid versus invalid when you provide it with a valid identifier.
    So ?someid=1&title=ignored is identical to ?someid=1&title=not+ignored when all you concern yourself with is the someid.


  •  

    Posting Permissions

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