问题
I'm converting my blog from movable type to wordpress.There are several thousand entries, and thankfully I am able to keep (almost) the same permalinks.
I know that with some clever .htaccess
wizardry, I should be able to redirect my URLs, but I can't for the life of me figure out what the statement(s) should be.I have over 20,000 entries, so redirects on individual pages is not ideal.
Here's what I need to do:
I have a bunch of URLs like this:
http://example.com/posttype/2013/05/04/story_name_and_such_.php
I need to :
if(extension is .php) {
1. Convert underscores to hypens in the filename.
2. Remove the file extension.
3. Remove trailing hypens.
}
The above would end up as such:
http://example.com/posttype/2013/05/04/story-name-and-such
Anyone done something similar to this? I could really use the help on this one!
回答1:
How about something like this, in the htaccess file in your document root:
RewriteEngine On
RewriteRule ^(.+)_(.+)\.php /$1-$2.php [L,R=301]
RewriteRule ^(.+)_\.php /$1.php [L,R=301]
RewriteRule ^(.+)\.php /$1 [L,R=301]
来源:https://stackoverflow.com/questions/18564065/htaccess-rewrite-underscores-to-hypens-strip-extension-remove-trailing-unde