Wordpress - Show my blog along with main site - php

I already have my main PHP based website running in the root folder of my website. Lets call it www.example.com. I have about few pages. Some of the navigation links are:
Home | Services | About Us | Contact Us
I wanted to add a Wordpress blog to this.. So heres what I did.
Home | Blog | Services | About Us | Contact Us
Please note that I have now created a sub-folder called "blog" in the root folder of the website and I have uploaded all the Wordpress "files" into the blog folder. So if I want to access my blog, as of now, I would visit: www.example.com/blog
So far, its ok. Now when I add new posts to the blog, I do NOT want people to see the "/blog" in the URL, when they try to read the posts. I went through the following link, but it does not help: Giving WordPress Its Own Directory
The above link will help if people just want to host their Wordpress site and nothing else. Its just helpful to keep the root folder clean and still access the URL from the root folder. But thats not the case with me. I already have PHP based website running in root folder. I just want
the blog to be an addition, yet skip showing that its added in another folder.
I made the following changes as well in admin panel of wordpress:
In "Settings > General" page:
WordPress Address (URL): www.example.com/blog
Site Address (URL): www.example.com
In "Permalink Settings" page, chose this option: http://www.example.com/sample-post/
Now, the home page & other pages load fine.
THE PROBLEM:
When I visit: www.example.com/blog, it says:
"This is somewhat embarrassing, isn’t it?
It seems we can’t find what you’re looking for. Perhaps searching, or one of the links below, can help."
I do not understand why I see the above when I expect to see the post. There is a sample post of Hello Word. I expected to see a link to that, but that did not happen. Why is this happening?
Further, if I click on the Home link, it gets me to the homepage of the website, which is correct. But if I click on the "Sample Page" menu link or "Hello World" link under "RECENT POSTS", the following URL appears in address bar:
www.example.com/hello-world/
But, it does NOT show me the post. Instead it loads the index.php page of the root folder of my website, which should not happen. It appears as if the CSS file is not loaded as it removed all the CSS. So the index.php page's CSS stripped version appears when I visit: www.example.com/hello-world/
I have tried to find solutions for this, but all of them lead to the "Giving WordPress Its Own Directory" post. And the solution mentioned in that page, does not apply in my case. How can this be solved? All help is appreciated.
Thank you.

Method I
This would be dirty, and I'm not sure if this would even work, but try to do the folowings (I hope your site is procedural and you're not using any framework, otherwise this would complicate things a little):
Put the blog in your document root, so all WP links would work "naturally".
Put your site files into site/ subfolder.
Now we'll do some magic with .htaccess and rewrite your "site" links by putting the following code right after RewriteEngine on:
# do this for all pages of your site:
RewriteRule ^services/?$ /site/services/$1 [L,QSA]
# now let's try to trick WordPress and swap / with /blog
# so users will see /blog in adressbar, but we'll show the WP homepage
RewriteRule ^blog/(.*)?$ /$1 [L,QSA]
Now we should make WP think that /blog is actually /, so it would not make any suspicions. Put the following script in the index.php file of Wordpress, before any other code:
if( $_SERVER['REQUEST_URI'] == '/' ){ // original site homepage requested
include('./site/index.php');
exit;
}
if( trim($_SERVER['REQUEST_URI'], '/') == 'blog' ){
$_SERVER['REQUEST_URI'] = '/';
$_SERVER['QUERY_STRING'] = '';
}
I haven't tested anything, but you should play around with these.
Method II
I'm not an advanced WP user, but if playing around with permalinks suggestion from #bingjie2680's answer would change the urls, than you can then try only one more thing in addition to that answer. Add something similar to the following lines to .htaccess that's in your document root (not WP's one):
RewriteCond %{REQUEST_URI} !^(services|about|or_other_stuff)/?$
# Rewrite the request to call the WP index.php.
RewriteRule ^(.*)$ /blog/index.php/$1 [L,QSA]
Maybe there are other methods, maybe the true solution would mix both of this.
Keep trying.

I don't think there would be a problem if you do the following things:
no need to change anything in your original site.
create a folder called blog in your root directory and place all wordpress files in here.
follow the quick five-step to set up your blog
your wordpress url and site url should both be yourdomain.com/blog
In "Permalink Settings" page, chose this option: www.example.com/sample-post/
keep your menu like: Home | Blog | Services | About Us | Contact Us
with 'blog' pointing to yourdomian.com/blog
Now if your click on the blog menu, your site url will be yourdomian.com/blog, but if you click on one of posts say 'hello world', then your url will be yourdomian.com/hello-world.

Related

How to deindex URLs which belong to your site but aren't listed in the WordPress "pages" section?

I am wondering how I could take out of the Google index any URL which is not listed in the "pages" section in WordPress but still belongs to my site.
As you may see in the attachment, a link to the "admin" page appears in the SERP snippet related to my website, which is very inconvenient! It is an internal "ghost" page which should not appear to potential customers...
The URL in question is https://www.myoutlet.lt/ru/author/admin/ but, as I said, it does not exist in the WordPress back-end, so I am quite clueless. I cannot just deindex it by means of Yoast or similar, because I can´t accede to the back-end of this page!
I suppose that I should add some code to the .htaccess file, but I have not found any viable solution so far.
SERP Snippet
This link shows how to disable author pages:
https://kb.yoast.com/kb/disable-enable-author-archives/
And
You can noindex the pages using a robots.txt file.
Robots are any type of “bot” that visits websites on the Internet. The most common example is search engine crawlers. These bots “crawl” around the web to help search engines like Google index and rank the billions of pages on the Internet.
You can create a robots.txt file using the Yoast Plugin
Steps Below:
Step 1:
Step 2:
Step 3:
Now disallow the page you need to noindex:
Add this to your robots.txt file
Disallow: /ru/author/admin/

Can't visit anchored links in WordPress

I'm trying to build my theme for a school project and I'm using wordpress to set up a blog.
I don't have intentions of sharing this theme so all of the website design is already premade.
The problem occurs when I try to enter the blog.php file from my navigation. My homepage is index.php file from which i navigate to the blog site. Everytime I do so the index page refreshes instead of opening the blog.php file, but the browser search bar shows the directory location as blog.php.
Wordpress does not work on a process of just make a file and it can be used as a page. Instead, it uses template structure. Meaning blog.php is not a page, it is a template (if you have setup the file structure correctly). Putting link through a menu to "blog.php", confuses WordPress and it just displays the default page of the site. You should make each page through WP "Pages" section.
StackOverflow hates WordPress questions. WordPress has its own help forum. I suggest googling for it and ask questions there.
If I mistook your question here are some helpful links:
https://developer.wordpress.org/themes/basics/template-hierarchy/
https://codex.wordpress.org/Theme_Development

How to change the blog page url on wordpress

My website like www.example.com. I need to go to redirect a url as 'press.example.com' when click on the blog. I went through a lot of reference but could not find any solution. How can I change the url for only the blog page. Any help would be appreciated.
Normally this is done by creating a custom menu item which links to an external link, as this is a separate site the blog settings in the example.com website are not relevant in this case.

wordpress seo friendly url doesn't recognise template

I have a website where there are profiles. I have changed the .htaccess so it give me a nice URL back, for example.
SEO unfriendly URL:
www.domain.com/index.php?page_id=216&acctype=trainer&stname=name
of trainer (with - instead of spaces).
Now I managed to get it like the following:
www.domain.com/profiel/trainer/name-of-trainer
My .htaccess looks like this:
RewriteRule ^profiel/([^/]*)/([^/]*)$ index.php?page_id=216&acctype=$1&stname=$2 [L]
All I get is that the page is not found.
I have a page in WordPress (profiel) and have a template linked to that page, could it be that the acctype (type of account), is making it that the template is not being found?
Hope that the explanation is clear, if not, please ask.
Hope some one can help.
I have setup the permalinks correctly, because the url is showing, it only doesn't show the correct template, it should show more detailed info about that specific user.
I am wondering what is going wrong, have no clue at this tried.
The wordpress post and page urls are stored into database too.
When you change your url rewrite on .htaccess that changes base redirection only. You need to change permalink on Settings > Permalink Settings > Select your url pattern By using this the wordpress automatically change .htaccess and all post url and page url on database to.
I don't think you need to change in your .htaccess file to make the URL SEO friendly. Just login the admin panel
Settings > Permalink Settings > Select Post Name from the given options
Using this way you can make URL SEO friendly in WordPress.

Disable wordpress auto search for related posts

I am working on making urls like example.com/profile/username to work where example.com runs Wordpress(latest release). The install is on root. I wrote a plugin hook to catch template_redirect and I examine the URL to see if it is a profile request and then I show the profile.
But, when a URL that does not exist is typed, Wordpress does an auto search for related posts before triggering a 404 or template redirect.
For example, example.com/profile/foobar goes to another page which has foobar in its title like example.com/2009/10/1/foobar
How do I stop this from happening?
I haven't upgraded my wordpress blog in probably 2 years (posts or software), but my first thought was a .htaccess file. I looked at the main one and found:
But that doesn't explain search results right off. So I found this file
/wp-includes/rewrite.php
which has a few dealings with permalinks and search results. The main one I spotted was:
// Search
$search_structure = $this->get_search_permastruct();
$search_rewrite = $this->generate_rewrite_rules($search_structure, EP_SEARCH);
$search_rewrite = apply_filters('search_rewrite_rules', $search_rewrite);
Basically, if all searches are turned into permalinks and all permalinks are rewritten to a script that creates a generic page, you get the /foobar page...
I'll keep you posted on what I find.

Categories