rewrite rule my urls in wordpress - wordpress

i search a lot in the web and read many tuts and references but could not solve my problem! here is my problem: in my wordpress site i have some urls like this:
localhost/mysite/articles/?arc=8892
i have this url because in my php code i validate that article:
<?php
$article = wp_getpost($_GET['arc']); //arc = 8892
if($article->post_type == 'article')
//process article....
which 8892 is id of a post with article custom post type! also i have a plugin names custom post type permalink which set this style for this post type.
what i wanna do is rewrite below url to current urls:
localhost/mysite/article/8892
without any change in my php code.
in my htaccess code i have this but does not work:
RewriteRule ^articles/?([0-9]+)/?$ /articles/?arc=$1 [NC]

You don't have to write .htaccess manually, wordpress does it for you.
Just go to http://path/to/your/blog/wp-admin/options-permalink.php in yout browser and use one of the predefined url strucutres or write a custom one yourself.

Related

Change a specific url to other url in wordpress using function or htaccess

Hi i have a woocommerce product and its url is http://localhost/project/product/my-product/
For this specific url i want to change the url in to
http://localhost/project/my-product/ .
Or some one take http://localhost/project/my-product/ he need to see http://localhost/project/product/my-product/ content without changing .
Is that possible using htaccess or any othe function
you can hook up into redirect rules, here is an article for that https://rudrastyh.com/wordpress/change-specific-urls.html

Alter GET variable in Wordpress

I am working on a wordpress self-hosted website, with the standard .htaccess settings:
In the website, I have a page called "animalpage". Using my rewrite settings, it is shown in the address bar as http://www.example.com/animalpage.
I am using a custom page template and am processing some things, which include the use of GET variables. For instance:
if (isset($_GET=['word'])) { echo $_GET['word]; } So, http://www.example.com/animalpage?word=cat will display "cat".
The problem I have is rewriting the URL so that it can look like: http://www.example.com/animalpage/dog, still being able to access "dog" as the GET variable.
I am not too good with mod_rewrite rules to begin with, but working from within a wordpress installation is throwing me an extra curveball.
Does anyone know what I need to add to my .htaccess to achieve this?
Thank you!
Old version:
RewriteRule ^animalpage/([a-z0-9]+)/?$ animalpage?word=$1 [NC,QSA]
Revisited:
RewriteRule ^animalpage/([^/])/?$ animalpage?word=$1 [NC,L,QSA]

.htaccess rewrite url with string URI is number

I have a website which was built with wordpress CMS. I want to change it to another theme with custom post type.
it's current url looks like:
mysite.com/1234 - links for posts - 1234 is id of the post
mysite.com/topic/cate-name - is link for categories
mysite.com/tag/tag-name - link for tags
now when i change to new theme and convert all post type, categories, tags, it causes some change likes:
mysite.com//video/1234
mysite.com/cate-vid/cat-name
mysite.com/tag-vid/tag-name
Please help me to rewrite my url with .htaccess for both apache and nginx serivce.
Thank you very much!

301 Redirect only Posts not Pages

I am looking to redirect all the posts and not pages and custom post types from old domain to new domain. So all posts for instance
http://www.example.com/post1 should go to http://example1.com/post1
http://www.example.com/post1 should go to http://example1.com/post1
The pages i.e. http://www.example.com/page1 should still be functional
I can find alot of answers on moving blog into sub directory along with moving all the links but not for moving just the posts and not the pages
Edit
There are over 1000 posts so I am looking for a dynamic way of doing this
Thank you for your help
The hack I finally end up using was
Add ob_start to single.php as first line even before get_header()
Add following code in functions.php
change example.com with your site domain name
add_action('wp_head','redirectme');
function redirectme() {
if ('post' === get_post_type()){
wp_redirect( 'http://example.com' . $_SERVER['REQUEST_URI'] , 301 ); exit;
}
}
I don´t think this is possible with this URL schema. .htaccess (or the Apache behind it) doesn´t know if post1 is a post or page. How shall it then redirect on this base?
If you would change the URL structure for pages alone (I don´t think this is possible by default, or am I wrong?) you could target their URL scheme and redirect.
To access the old pages (with the new URL) you could then use a "broken link checker" plugin.
Update: You could possibly use the hook described here to check wether the called post is a post or page and then use wp_redirect to call your new URL.

Rewrite category wordpress

Is it possible to rewrite only one category ?
I have a category "Photos" and just for this category.
I just want to rewrite it from /category/photos to /photos
You can do it with WP Rewrite API.
Add this to functions.php
add_action('init', 'register_rewrites');
function register_rewrites() {
add_rewrite_rule('^photos$', 'index.php?category_name=photos','top');
}
Remember to reload your rewrite settings: go to Settings -> Permalinks and click on Save button - no changes needed.
The Yoast SEO plugin has this function build in, I recommend this plugin in general.
no-category-base-wpml only does this
If you don't want to install a plugin for this. Around the web there are many tutorials which do this:
http://thisismyurl.com/6704/remove-category-url-wordpress/
http://www.webdevtuts.net/php/how-to-remove-category-from-wordpress-url-structure/
http://www.wprecipes.com/how-to-remove-category-from-your-wordpress-url
Too enable this for just one category I would advise the following:
create a page called photos.
create a theme template page for this photo page
In is set up a new query_posts* getting the category 'photos'
Include the category.php file.
assign that template to the photo page.
Not tested but should work. Because the page has the correct URL and should include the category. Questions, aks.
*query_posts is bad for performance if you want to do it totally correct use the pre_get_posts filter. It's requires more knowledge.

Resources