Changing the structure of WordPress URLs when working with 301 redirects using mod_rewrite

I currently have a blog configured using WordPress using these URLs:

www.domain.com/blog/?pid=384092817

That was before I knew something. There is a significant amount of content there, and I want to change my URL structure to:

www.domain.com/my-post-title-384092817

Is there a way to configure my .htaccess and mod rewrite, so when users go to the first URL, they get a 301 redirect to the second URL? I know to change the WordPress address (URL) setting from www.domain.com/blog to www.domain.com and setting the permalink to /% postname% -% post_id%, but how do I tell the old URLs for redirects to new ones?

+3
source share
2 answers

Depending on your version of WP, you can simply use the Permalink redirect plugin - it should do the trick for you in WordPress without mod_rewrite, however, with WordPress 2.3, many of these should work automatically . At this point, you just need to redirect all your / blog / ... requests to a route that you can do via mod_rewrite something like this:

RewriteRule ^blog(.*) $1 [QSA]
+3
source

Do you really mean that when users go to the second URL, it will be rewritten first? This can be done using

RewriteRule /blog/.+-(\d+)$ /blog/?pid=$1

301 URL- , .htaccess. , Apache mod_rewrite , , URL. PHP.

: , , , . RewriteMap, , Apache , , , PHP , , , , URL- . , - PHP.

+4

Source: https://habr.com/ru/post/1704619/


All Articles