Redirect "cropped" url to canonized url (Avoid duplicate url)

Asked

Viewed 76 times

0

  • Post part of . htaccess Rewrite URL

  • I believe this is the part to be corrected: RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/([0-9]+)/([^/]+)/?$ /entry.php?w=$1&e_id=$2$3 [L]

  • If you use the rel=Canonical attribute correctly on your pages you won’t have to worry about duplicate Urls in Google’s index, it’s just a suggestion, I don’t know if it solves your problem.

  • I get it. But in addition, I would like to prevent the user from changing the url, for example: http://meusite.com/cidade/495/insults.

  • 1

    It seems to me that this is not the case for . htaccess, but rather for solving in PHP, in the same part where the post number is processed. Simply if you don’t hit the URL with the BD, redirect, maybe it’s about 1 or 2 lines of code at most.

  • Petrus, the best is you [Dit] the question, adding the information you are giving through comments, and then notifying the other user using the arroba "@Username, I edited the question etc, etc," (the author of the post is always notified)

  • @Bacco also thought about it, but from what I noticed, the url is not stored in the BD, it is generated by php in each request: 
 $url = "$prefix$weblog/$e_id/$stripped_title$extras";


  • It doesn’t make any sense to me. Number 495, "privacy policy", etc are saved somewhere, right? It would only be compared to the URL being accessed.

  • However, definitely . htaccess not the way to it. If you can post the part that picks up the URL and shows the right post, we can try to help you. Is using some ready structure such as wordpress or similar?

  • @brasofilo I will edit the question as soon as I can express the problem concisely, the comments are helping.

  • @Bacco The number "495" yes, is the $e_id. the "privacy policy" is generated from the post title "Privacy Policy", if I change the title, the url changes automatically. What I meant to say is that the url is not stored independently in a separate table column.

  • @Bacco I’m using the system "Bloghoster". In Wordpress he already does it by default. I’m trying to adapt this functionality to this system.

  • I have a feeling something like this would solve if ( $_SERVER['REQUEST_URI'] != $url ) { header( "Location: $url" ) } assuming $url is generated in this way that you posted. That is, if what the person requested is not the correct URL, redirect. Of course, in this case you would have to reassemble the URL by the ID obtained. Maybe you already have a function in the Bloghoster itself that at least generates the url. It is a very simple thing to do, but it depends solely and exclusively on seeing the relevant code that processes the URL to be able to answer.

  • @Bacco I believe this is the part of the code you are referring to: [entry.php] (http://pastebin.com/afcEdnjX) and [functions.php] (http://pastebin.com/80A8HqSe)

  • @Petruscintrakamaleao seems to me that $entry_info has everything you need, would only compare the Slug matches the title itself, and by that logic in the redirect that already has there. I did not try to understand right some things repeated in this code, because I would have to read it calmly, but I can dry it well, and work as you want with very few lines, would be well what I said in the previous comment same.

Show 10 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.