Context: I am building the blog section of a website in Symfony2.
Question:
Which is the best way to link a specific comment in a news? How should I define the route structure?
Examples:
Single News Url:
example.com/news/{news_id}
Single News + Comment Url:
example.com/news/{news_id}/comment/{comment_id}
or
example.com/news/{news_id}#comment-{comment_id}
or
example.com/news/{news_id}?comment={comment_id}
These are just some suggestions...
VERY IMPORTANT:
I need to use both the news_id and the comment_id inside a controller. They need to be retrievable/available.
Structure of the suggested links will have different outcomes, and your comment_id variable wont be available for your script in all cases.
Something important for news page they affect SEO differently.
first 2 variants of the url.
example.com/news/{news_id}/comment/{comment_id}
example.com/news/{news_id}?comment={comment_id}
commment_id WILL be available in your script. Symfony will pass to your controller or you will be able to get it from the Request object (or from $_GET variable - but don't do this)
browser WILL NOT
don't worry you WON'T have duplicate content if you don't create both routes for the same page.
from SEO point of view you are creating a separate page for each comment (I know you are not), that's the way what google would except from that url structure. To avoid duplicate content just add canonical link element to HEAD to point to the root url <link rel="canonical" href="example.com/news/{news_id}" />
hashtag url variant
example.com/news/{news_id}#comment-{comment_id}
comment_id WILL NOT be available in your script. Everything after # is handler directly by browser, and it WILL NOT send it to the server at all. The comment_id value WILL still be available by javascript (this is how stackoverflow does it)
browser WILL try to move(scroll) to a portion of the html, where the Key after # is used as ID.. eg. <div id="comment_id-123">. If you don't have element with the ID in your markup, it will stay on top.
solution
Based on assumption that you don't want separate page for each comment, and you only need the comment_id for pagination of the comments.
Right solution would be to use the # variant of URL.
load the page with just the news_id
after page load, do an ajax call with the comment_id parameter for comments, or for 1st page if there is no parameter.
change the comment section with returned information about pages etc.
add loader images, there so user will know whats happening as this increases UX.
more SEO suitable alternative
If you want better SEO, more suitable url would be not with ids but with slugs, and also without unnecessary words. I personally suggest this:
example.com/n/{news_slug}#{comment_title_slug}-{comment_id}
// would become something like1
example.com/n/answer-to-life-is-awesome#yeah-it-was-a-great-book-5435335435
If you can handle the parsing, and db querying, it could be also without the /n prefix.
You mixed two different concepts:
Links
The two following links carry the same parameters, news and comment ids:
example.com/news/{news_id}/comment/{comment_id}
or
example.com/news/{news_id}?comment={comment_id}
A browser opening these URLs will not scroll the page.
Links with anchor
This following link have only one parameter, news id, and it uses an anchor:
example.com/news/{news_id}#comment-{comment_id}
A browser opening this URL will scroll to the anchor.
So it depends of your need, if you want that the visitors' browsers scroll to the comment, use an anchor (it's also possible with Javascript).
Here are valid anchors:
<div id="comment-42">...</div>
or
<p>...</p>
Here is a link leading to this answer: https://stackoverflow.com/questions/33176341/php-url-structure-to-link-specific-comment/33179630#33179630
See also #! URLs.
I believe the better way is using #comment-{comment_id} because the duplicate URLs problem that the other 2 URLs may cause.
Related
I have a PHP website where every page can be accessed either by page ID or by page name:
http://domain/page_id=ID
http://domain/page=NAME
The problem is that Google treats this as duplicated content. What is the best practice to avoid duplicate content in the case? Will 303 redirect will be better than entirely avoiding two different URLs to lead to the same page?
According to Google:
In the world of content management and online shopping systems, it's
common for the same content to be accessed through multiple URLs.
Therefore,
Indicate the preferred URL with the rel="canonical" link element
Suppose you want
http://blog.example.com/dresses/green-dresses-are-awesome/ to be the
preferred URL, even though a variety of URLs can access this content.
You can indicate this to search engines as follows:
Mark up the canonical page and any other variants with a
rel="canonical" link element. Add a element with the attribute
rel="canonical" to the section of these pages:
This indicates the preferred URL to use to access the green dress
post, so that the search results will be more likely to show users
that URL structure. (Note: We attempt to respect this, but cannot
guarantee this in all cases.)
So, all you need to do is to add the canonical link element to the <head> section of your pages with absolute paths.
I have quite large amount of the same content that needs to be repeated on all 28 product pages of a website that I am working on.
In terms of SEO, I know web sites like Google don't like this and just see this as duplicated content.
I thought using a <?php include 'page.php' ?> would resolve this but this just writes the text as HTML and therefore makes no impact meaning it would still be seen as duplicated content.
I know I can use <META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW"> so that bots don't read these pages but if I was to do this, the only page it would be following is the homepage.
What would be the best way to get around this?
Is it possible to use the NOFOLLOW method for certain sections of the website?
Any suggestions on this would be very helpful!
My suggestion would be to think about your visitors first, not Google and their SEO requirements. Is the repetition of content beneficial to the visitors, then do it.
In SEO terms: if you duplicated content 28 times it might be seen as the same content, so it's not counted seperately. So what? It IS the same content, and you know it.
Websites are made for visitors in the first place, and search engines secondly. You should take SEO optimization in consideration, but don't let it dictate the user experience of your website. Make the best website you can, for real people.
Google understands boilerplate content, so if you need the information on the pages, then so be it.
Google is generally quite good at recognizing "boilerplate text" (text
which you repeat on many pages) and treating it appropriately. I
wouldn't worry about having to place a disclaimer on your pages. If
you want to make it clearer to search engines that it's not relevant
to your content, you could also just place the text in an image
(personally, I'd just place the text on the pages normally).
https://www.seroundtable.com/google-duplicate-text-14515.html
There's a better way to do this.
Combine the 28 product pages into 1 page that serves dynamic content from a database.
So each time you go to this single page, you pass a particular product ID (through a query string parameter, form data, a cookie, or a SESSION variable).
So instead of:
product_bicycle.php
product_skateboard.php
product_widget.php
etc.
You could have:
products.php?id=123
products.php?id=234
products.php?id=345
etc.
If all your product information in stored in raw HTML files, you'd just have to put those into a MySQL database. Create a table called products. Put in it a column called something like "Product_ID" which would hold the values like "123", "234", and "345" shown above. And put in another column like "Product_Details" which would hold the HTML of the product description.
When the page loads, you'd want PHP to do the following things:
Show the HTML for the page header, logo, navigation tabs, and other shared items. (Use the PHP "echo" or "print" statement - or just include it in the raw HTML of the page.)
Use the $_GET, $_POST, $_COOKIE, or $_REQUEST variables to get the product ID passed to the page. For example, "$id = $_GET['id'];"
Do a SQL query to pull up the product record based on the ID.
Show the description of the product from the result set.
I have a forum whereby links to a thread looks like
http://www.website.com/comments.php?topic_id=1
How can I make it look like this
http://www.website.com/1046302/some-link-desc#12154109
so that when such links are given out, the user is taken directly to that particular comment.
I'm particular about the #12154109 . The other part of the URL /1046302/some-link-desc is achieved through .htaccess configuration.
Question Update
What is the best way to get the unique number ? Do I use a timestamp or a concatenation of the topic_id and comment_id ?
You would have to apply a the following tag in the comment portion of your template.
<a name"1215409"></a>
of course the number would be set to the comment id.
You're not going to be able to do this through htaccess. The fragment, the #something part of the URL, tells the client specifics on how to handle the content that it was served, in the case of anchors, it tells the browser where to seek to in the page. The fragment is never sent to the server, so apache never sees it, and thus nothing in the htaccess file can match against it or use it in any way.
Fragments are also used by javascript which can look at the URL to pull stuff out of the fragment or to force a script to rerun by reloading the page with a different fragment.
You can, however, send fragments to the client from the server, but there's no way to know whether the client already has the fragment or not. But the content itself will need to have the fragments in the links, htaccess isn't going to know which anchors are in the actual content that ends up being served.
I'm trying to make the URLs of my site SEO and user friendly. It is basically a static corporate website but for the side menu I am passing some variables through URL to show the sub menu of main selected menu.
For example: Offshore staffing is one of the main menu items and one of its sub menu items is Programmers. When someone clicks Programmers I will pass the id of main menu and sub menu through URL to collapse all other menus and promote the opened menu.
I want to mask something like ?id=4&sid=4 at the end of every URL. Can't use hidden input element because I am modifying this site and the developer who actually built that site didn't use forms.
You're looking for using a .htaccess file to rewrite URL's. For example stackoverflow might use something like this:
RewriteEngine on
RewriteRule ^questions/([0-9]+)/([_\-\&\'\,\+A-Za-z0-9-]+)?$ questions.php?q=$1
This would make both stackoverflow.com/questsions/1234/a-title-of-a-page and stackoverflow.com/questions.php?q=1234 the same page, so on your website you would need to use the "tidy" version of the URL (the first one)
A lot more can be read into this and you can customize you're URL's to what you require. For example, a few places to read up on it include:
http://httpd.apache.org/docs/2.0/misc/rewriteguide.html
http://www.easymodrewrite.com/
Generally a good way to do this (so that you don't have lots of ID's in your URL's) is to store a "URL friendly" name of the page (e.g. "name-of-page") in your database, then when the page is requested, just search your database for that name and you'll know what ID it relates to.
Translate the ID's to the words they stand for when writing the links, and use mod_rewrite to pass them back to PHP when they're visited, where you do a lookup based on the words, and find the ID again.
So the link becomes /offshore/programmers, then you do a lookup for the ID's of "offshore" and "programmers" and show the appropriate content.
What do you mean by "masking"? Is URL-rewriting, what you are searching for? If yes, you need to append the alias (e.g. "programmers") to the URL, instead of the GET-params. Those will be translated to GET-params via URL-rewriting and then matched to an ID via PHP.
Here's the situation.
I have a site where clicking hyperlinks within a certain div makes a jQuery function get the content of a div from a separate page. Because of this, the URL don't change. I need it to change as well as writing an entry in history.
My pages are setup like this (not sure this is the smartest way of going though)
access.php (main logon)
new-user.php
forgot-pass.php
index.php
controlpanel.php
etcetc. Now, all of these pages are reachable on their own and are mainly identical and all contain a div called "container". When clicking links, the content from this div gets erased and the content from the coresponding div (container) gets loaded from the file of the URL (href). I'm terrible at explaining..
So basically, what I need is some javascript that picks up the href link address and just pastes it in the url bar at the same time as it creates an entry in history so the back and forth buttons work.
I plan on extending this in a while as well, translating query strings as well. But there are a few constant static pages I need to take care of first. Any help would be very appreciated! :)
You are not allowed to change the entire URL by JavaScript but you can use URL hashes. I recommend you the browser history plug-in. You can simply register a handler to react on URL changes and load your corresponding content via ajax.
Have you looked at the jquery address plugin? Look at the examples. Is this similar to what you want?
It's not possible with "normal urls" (we must wait for a new generation of browsers...)
But there is a "trick": playing with anchors.
A link like "same_page.php#anchor" does not reload the page, but act on both the history and the adress bar.
So, if instead of having url like "page.php?param=lorem", you could have "page.php#param=lorem", you have your solution :)