Wordpress Custom Permalinks rewrite - php

I have a page called blog .
I would like all of the posts on the site to come after this page like:
www.site.com/blog/
www.site.com/blog/blog-post
I can edit the permalinks .
but when I try to save them with this custom structure /blog/%postname% .
it just says they are updated but doesnt actually update them, my guess is that there is some kind of conflict because I have a page already called blog. has anyone come up against this issue and has anyone been able to resolve it.
so far my only solution is to create a custom permalink using blog1 and then try to use htaccess rewriting to change blog1 into blog but even that is not working, maybe I am doing something wrong but this is my rewrite, which does rewrite albeit to a 404 page
RewriteRule ^blog1/(.*)$ /blog/$1 [L,R]

Related

Redirect Wordpress post url after changing categories

I want to add a parent category to my existing posts categories in Wordpress. But i need the old URLs to continue working.
So the URL structure is now:
example.com/category/postname
And by adding a parent category, it will turn into:
example.com/new-parent-category/category/postname
How can i make sure that the old URLs keep working?
I don´t want to write a custom redirect for every single post.
Could you maybe accomplish this with a regex redirect in htaccess?
In file .htaccess, You can try this way:
RewriteRule ^category/(.*)$ /new-parent-category/category/$1 [R=301,NC,L]
In this way all the links that contain the "category" will be redirected to "/new-parent-category/category/.."
You can visit this page to read more..
Read more..

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.

Using .htaccess in Wordpress to rewrite category to a static url

I've been looking for hours trying to find a solution that actually fits with my desire, and I can't make it work. What I want is, using WordPress, to have a /blog/ URL which actually shows the content of /category/blog/. I know that this can be done by creating a custom template for a page called "blog" and adding a loop to show the content of "category", but I don't want that. I want to show at /blog/ the contents of /category/blog, so /category/blog/page/2 can be accessed from /blog/page/2...
How can this be achieved with .htaccess? I've been trying tons of different options and it's just redirecting "blog" or "blog/" to the category page. This is the rule I'm trying:
RewriteRule ^(blog)/?$ /category/blog [L]
Thanks for your time and best regards.

Wordpress - Show my blog along with main site

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.

How to use mod_rewrite with Wordpress?

I'm running a wordpress installation on the root dir of my website test.com
Wordpress is using url's like: test.com/information/ and I also added some custom parameters like: test.com/information/?about=product
I tried to use the mod-rewrite generator at http://www.generateit.net/mod-rewrite/ to change my custom urls to test.com/information/about/product but keep receiving a wordpress 404 error.
Is there a solution to my problem?
All answers wrong. Login to admin area. On the left menu, under settings find permalinks. You can choose or add proper settings there.
I agree with #borayeris - Wordpress has it's own permalinks page under Settings - use that.
If you are already using pretty permalinks, make an about page then make it the parent page of all your product pages.
Or use the rule:
RewriteRule ^information/about/([^/]+)/?$ information/?about=$1 [L,NC]

Categories