I am having some issues with my website indexing. The thing is that I have a Website of news using PHP and MySQL. Every time that I create a news post a URL like this link the post.
Example:
//pretty URL
//nameOfSite + PostId + newsTitle
mYpagExample.com/5/the-obama-lagacy
Google is indexing this 2 ways
mYpagExample.com/5/ // Ii dont want this to be indexed
mYpagExample.com/5/the-obama-lagacy
Even though I am declaring the original URL as canonical it seems to be no enough.
<link rel="canonical" href="http://mYpagExample.com/5/the-obama-lagacy">
NOTE: I am using .htaccess for the pretty URLs.
Can someone tell me how I can fix this?
Edited:
this is the link of the post that comes from the DB example:
<?php echo $title?>
.htaccess file
RewriteEngine on
# Get the request URL by the user
RewriteRule ^([a-zA-Z0-9/]+)$ index.php?view=$1**
Related
I have a page where I am loading up a JSON file and matching data based on a users search.
The caveat however, is that I want to have really clean URLs for these results without actually making a new page for them. (For the life of me I don't know what the terminology for this is)
So when a user goes to website.com/names/adrian it will just land on /names/ and load the data based on "adrian".
You can do that with apache's rewrite rule:
RewriteEngine on
RewriteRule ^(names\/[a-z0-9A-Z-_]+)$ names.php?name=$1
Add this to your .htaccess file
It will send example.com/names/aName as get request to names.php.
And you can get that with $_GET["name"]; in names.php
By the way, you can see regex result in here: https://regexr.com/415mq
I'm creating a simple, wordpresslike cms and keep all parts of a page in a table and load them using a template page named view.php following by a $_GET variable, for example:
sky.com/view.php?article=how-to-do-something
But as I can see on wordpress sites there is no 'view.php' template file and $_GET variables inside url. There is pure domain name and title of an article.
I suppose this is a better approach for SEO engines.
What is the general way to do this and how can I use the same. Is there a function to create a file on fly, or maybe a hidden file system...
The same is with stackoverflow.com. There is no view template inside url, but I'm rather sure it uses database table for storing parts of a page.
I tried with .htaccess file and this accepted solution but got the error 500 - internal server error.
By way of explanation; what stackoverflow.com probably does is something like this:
URL:
https://stackoverflow.com/questions/44654672/cms-without-view-template-inside-url
Actual URL is first rewritten using mod_rewrite so that 1) the missing .php is added, and 2) the GET parameters are set:
RewriteEngine on
RewriteBase /
RewriteRule ^questions/([0-9]+) questions.php?qid=$1 [NC,L]
And so the questions.php page loads the question with id 44654672.
The above mod_rewrite says: take the URL, starting with questions/ and send that URL to questions.php, as well as saying: After questions/ take the number value and use that as the question id GET variable so that the PHP page loads the correct question from the database.
The wording in the URL is purely for SEO purposes.
You will notice that https://stackoverflow.com/questions/44654672 will also load your question correctly (*), but if you change the number value (even while keeping the words the same, ( such as https://stackoverflow.com/questions/44351172/cms-without-view-template-inside-url ) another question will be loaded from the database.
Putting the exact URL link into my answer makes it display the question title rather than URL
Think of it as the mod_rewrite is doing a find and replace search on the URL string. That's all.
I have a custom wordpress page that I wanted to make its url SEO friendly.
So I added some code using rewrite api to convert this url:
http://example.com/page1/?id=1234
to:
http://example.com/page2/1234
page1 is still there and first url still valid. page1 was not very descriptive so I though that since I'm rewriting the url I might as well rename the page too.
Everything on the website works fine, but when I recreated the sitmap xml file and resubmitted to google I was hoping google would forget the old url and start showing the new one. This was a few weeks ago and I'm still seeing old urls. Any idea how I can remove the old urls? Do I need to physically rename the page itself?
Please help.
Thanks
Since google has indexed old URLs, it will stay in their index unless you do something about it. There are two options you can handle.
If you want the old urls to coexist, you can do rel="canonical" on the old URL pages. Canonical will indicate that they are same pages with different urls.
Other option is doing 301 redirect. 301 indicates that the page has moved permanently and it helps search engines to carry over the SEO values of the old urls to the new ones. In due course search engines will index the new urls and old urls will go away. After a certain point in time, once you are sure that old URLs are not receiving any traffic, you can get rid of the redirect rule.
My site has pages like news.php, vidoes.php, products.php etc
The data for these pages are held in a MySQL database they have id, name, description and permalink
If a name is News Article Title or Boxing Match Video they permalinks would be news-article-title and boxing-match-video
Now on the news.php page there is a list of news articles and they are linked to read-news.php with ?id= and the article id beside it.
So a link looks like this www.mysite.com/read-news.php?id=2
On my read-news page I use a GET to get the id and then data for that article comes too.
How do change the links on the news.php page to come up as www.mysite.com/read-news/news-article-title.php and the URL to display the same when reading it.
I cant seem to find a tutorial that shows exactly what I need.
Any help please
Thank you
You have to use a .htaccess file (if you are on a Apache server and do not have access to the server itself, like in a shared hosting situation)
.htaccess is a simple textfile you make and place in the directory in which it controls the access, e.g. the redirection of URL's and has a lot of usable functionality.
With this you can have your URL's rewrited without the user noticing it.
Good for SEO purposes.
More info: http://httpd.apache.org/docs/current/mod/mod_rewrite.html
If you want a quick try, automatic generation is done at
http://www.webconfs.com/url-rewriting-tool.php
For last 4 days I´ve been trying to make a friendly url using .htaccess (mod_rewrite)
I have a some news on frontpage and link redirects to the full article on news_id.php
So mypage.com/local/news_id.php?newsid=37 should take the headline from the "headline" field
in phpmyadmin - for example mypage.com/local/police-stops-girl-fight-at-the-mall
my .htaccess code is
RewriteEngine on
RewriteRule ^local/([^/.]+)/?$/local/news_id.php?headline=$1 [L]
Some tutorials says I also have to edit the php link on frontpage which is
<?php echo $row ['headline']?
...but I've also stumbled on articles that says that I don´t need it and show this should do
it.
I've checked out if mod_rewrite is enabled at the server and it works fine.
Am I close or is this much more complicated than I think?
Previously you were fetching by id. Now you are attempting to fetch by title.
That's a fundamental difference in the way your article lookups will need to occur and what content will be in your urls.
It may be easier to start out with a simple experiment site. Get that working. Then convert your real site over once you've seen how it all works.