Web Analytics Made Easy -
StatCounter 301 Redirection from old article to the new - CodingForum

Announcement

Collapse
No announcement yet.

301 Redirection from old article to the new

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new 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:

    In addition, I can access the article no matter what the name is, like that:

    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?
    Need domain? Buy Cheap Domain at Rapid Host :)

  • #2
    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.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

    Comment


    • #3
      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?
      Need domain? Buy Cheap Domain at Rapid Host :)

      Comment


      • #4
        Post in the apache forum
        "Tango says double quotes with a single ( ' ) quote in the middle"
        '$Name says single quotes with a double ( " ) quote in the middle'
        "Tango says double quotes ( \" ) must escape a double quote"
        '$Name single quotes ( \' ) must escape a single quote'

        Comment


        • #5
          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

          Comment


          • #6
            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?
            Need domain? Buy Cheap Domain at Rapid Host :)

            Comment


            • #7
              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.
              PHP Code:
              header('HTTP/1.1 420 Enhance Your Calm'); 
              Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

              Comment


              • #8
                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.
                Need domain? Buy Cheap Domain at Rapid Host :)

                Comment


                • #9
                  2 days passed, any help?
                  Need domain? Buy Cheap Domain at Rapid Host :)

                  Comment


                  • #10
                    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.
                    PHP Code:
                    header('HTTP/1.1 420 Enhance Your Calm'); 
                    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

                    Comment

                    Working...
                    X
                    😀
                    🥰
                    🤢
                    😎
                    😡
                    👍
                    👎