Wordpress .htaccess rewrite - wordpress

I have wordpress installed. I want to customize permalink as following:
Category: http://my-domain/{category-name}/
Post: http://my-domain/{category-name}/{postname}/
Post with params: http://my-domain/{category-name}/{postname}/{param1}/
Post with params: http://my-domain/{category-name}/{postname}/{param1}/{param2}/
Can I do only use .htaccess?
Thanks!
P.S: Sorry for my bad English.

In the admin dashboard, customize the permanent links to
http://my-domain/%category%/%postname%/

In Wordpress you can do this through backend. Go to Settings-->Permalinks-->Custom Structure and insert:
%category%/%postname%
You can refer here
If you wish to use other subfolders you need to create .htaccess file (if you are using Apache) in your root folder and use url rewrite like this:
RedirectMatch 301 /old-directory/(.*) /new-directory/
Be sure mod_rewrite Apache module is enabled.

Related

Wordpress 301 Redirect

I have got one Wordpress blog site and I use permalink as:
%category%/%postname%.html
I want a change as:
%postname%.html
And now old urls (https://www.example.com/category/post-name.html) 301 redirect to (https://www.example.com/post-name.html).
How can I redirect with use .htaccess file?
Just go to wp-admin, then /settings, then /permalinks and select "Post name". More info on that here: https://codex.wordpress.org/Using_Permalinks
For 301 redirects you can write your own to your htaccess file but this is probably not as easy as using a plugin like Simple 301 Redirects.

htaccess 301 redirect entire directory

After migrating ta large static site to wordpress (as well as a reconstruction), I have a permalink structure that differs from the original directory structure, yet the new post slugs are the same as the original filenames. It's also worth mentioning that the permalink structure mimics the file extension of the old file path.
For example:
what was once (static directory)
www.example.com/old/path/file.htm
is now (wordpress permalink structure)
www.example.com/new/path/file.htm (note: permalink structure mimics the .htm extension)
My question: Is there a simple htaccess rewrite rule that can redirect visitors from /path/to/file/(file.htm) to /new/path/to/(file.htm), without having to create a redirect for each file?
Using mod_alias is even easier:
Redirect 301 /old /new
But if you have rewrite rules in your htaccess file already, then you need to stick with using mod_rewrite:
RewriteRule ^old/(.*)$ /new/$1 [L,R=301]

Redirect Wordpress Permalink in htaccess

I want to change the permalink structure of my site from /%postname%/ to /%category%/%post_id%/%postname%/ , and have the old backlinks redirect to the new structure (currently getting 404's). I have tried a couple of different redirection plugins (Redirection, 301 Simple Plugins) and I can't get them to work.
Can someone show me the rule to put in the htaccess file instead?
Thanks!
If you know the explicit category and post_id for a given postname, then you can create the redirects individually:
Redirect 301 /example-post-name-to-redirect/ /example-category/1234/example-post-name-to-redirect/
or using mod_rewrite (note, these rules must be before your wordpress rules:
RewriteRule ^example-post-name-to-redirect/$ /example-category/1234/example-post-name-to-redirect/ [L,R=301]
But the better solution is just using wordpress to do this for you, have you tried: UrbanGiraffe Redirection plugin, Scott Yang's Permalink Redirect WordPress Plugin, or Yoast's Permalink Redirect WordPress Plugin?
On the Redirection Wordpress Plugin you must add your old structure to Site->Permalink Migrations, something like this:
/%year%/%monthnum%/%postname%/
On the .htaccess file you must use regex like this one:
RedirectMatch 301 /^/\d{4}/\d{2}/(.*) https://yourdomain.com/$1/

Convert these rewrite apache rules to nginx

In my Wordpress, I changed the posts permalinks structure. In order to don't get 404 erros for the old links, I would like to redirect the old permalinks to the new permalinks. According to this, the following code must be added in my .htacess so that I can get the redirect working from old posts links to the new posts link:
RedirectMatch 301 ^/([0-9]{4})/([0-9]{2})/([^/]+).html$ http://myurl.com/$3
That's good, however, I don't use Apache – I use nginx. How can I convert this rules to nginx? I've already tried a apache to nginx online converter, with no success.
Thanks!
I believe this is what you want. "permanent" is 301 according to this page.
rewrite "^/([0-9]{4})/([0-9]{2})/([^/]+).html$" http://myurl.com/$3 permanent;

Changing Permalinks

I want to change my permalinks from /%year%/%monthnum%/%day%/%postname%/ to /%postname%/
but when I added the following to the .htaccess file, posts didn't redirect the way I thought they would:
RedirectMatch 301 /dddd/dd/dd/(.*) /$1
What do I need to put into my .htaccess file to make it work?
My site is http://SweatingTheBigStuff.com
I think everyone is missing the point here - I think #Daniel has changed his permalinks, and now wants to redirect old permalinks.
The problem is your RedirectMatch regex is only matching a literal 'd', not digits.
Personally I would use this instead;
RedirectMatch 301 ^/[0-9]{4}/[0-9]{2}/[0-9]{2}/(.+)$ /$1
However, #markratledge is right in saying that there are issues with using just the postname.
You don't go into any code to change permalinks; that's changing WP core files, you'll break things and you'll loose your changes on an upgrade. It's much easier than that: go to Wordpress/Dashboard/Setings/Permalinks. If your .htaccess isn't writable, you'll get a warning.
And, using only the postname in permalinks is not recommended for performance reasons: Using only Postname in Permalinks « WordPress Codex
A relevant answer to TheDeadMedic,
You could use a plugin called Redirection to redirected your old permalinks to new permalinks.
But if you need to change your permalinks from the old version to a new version, then follow markratledge's advice

Resources