Question

Is there a way to re-generate the way permalinks work? I mean everywhere inside a blog ( all plugins & stuff which use get_permalink() ).

I want to replace all links like http://domain.com/wordpress/post_type/post to http://domain.com/post_type/post

The rewrite rules & stuff are done by htaccess, so if i access http://domain.com/post_type/post form address bar it works, so i just need to change the way how get_permalink() goes.

Note : I can not move the files outside the /wordpress/ folder because in its root there is another html template.

Note2 : I tried some 301 redirects with regexp and i get redirect loop. So also if there is a way to change it with htaccess it would be great

Thanks a lot

Was it helpful?

Solution

I finally found. If you're checking the core you will see all filters https://core.trac.wordpress.org/browser/tags/3.5/wp-includes/link-template.php. For custom post types it's post_type_link filter and for posts it's post_link. There are a lot of useful stuff, if you're going to read the code. The solution for my problem is :

define( 'SERVER_ROOT', 'http://' . $_SERVER['SERVER_NAME'] );
define( 'INSTALL_URL', site_url() );

add_filter( 'post_type_link', 'pleasure_post_links', 99 );
function pleasure_post_links( $permalink ) {
  return str_replace( INSTALL_URL , SERVER_ROOT, $permalink);
}

The code above will make the link http://domain.com/wordpress_folder/custom_post_type to http://domain.com/custom_post_type.

Also you might need this in your root .htaccess ( in the root folder, not wordpress folder )

RewriteEngine On

RewriteRule   ^blog([^'"]+)?$  ./wordpress_folder/blog/$1 

Where blog is the custom post type name and wordpress_folder is the instalation folder of wordpress

I hope it will be useful for somebody, i almost spend two days looking for a solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top