Apache 使用htaccess和重写规则从url中删除字符串和日期

Apache 使用htaccess和重写规则从url中删除字符串和日期,apache,.htaccess,url,redirect,url-rewriting,Apache,.htaccess,Url,Redirect,Url Rewriting,我想替换我的url的一些部分,年-月和.html url扩展名 基本上我想要这个(旧url) 转向 https://newdomain.com/post-name-example/ 这个网址。我搜索过stackoverflow和许多其他网站,尝试将不同人群的不同答案混合在一起。我试着写我自己的规则,但我做不到。任何帮助都会非常感激。多谢各位 我试图删除.html扩展名 #1)redirect /file.html to /file RewriteCond %{THE_REQUEST} /([

我想替换我的url的一些部分,年-月和.html url扩展名

基本上我想要这个(旧url)

转向

https://newdomain.com/post-name-example/
这个网址。我搜索过stackoverflow和许多其他网站,尝试将不同人群的不同答案混合在一起。我试着写我自己的规则,但我做不到。任何帮助都会非常感激。多谢各位

我试图删除.html扩展名

#1)redirect /file.html to /file

RewriteCond %{THE_REQUEST} /([^.]+)\.html [NC]
RewriteRule ^ /%1 [NE,L,R]
此选项用于从url中删除日期格式

# REMOVE DATE FROM WP POST PERMALINKS
RedirectMatch 301 ^/wordpress/([0-9]+)/([0-9]+)/([0-9]+)/(.*)$ http://example.com/$4

http://example.com/wordpress/2012/04/12/post-name/

..to elegance:

http://example.com/post-name/
我的htaccess文件是这样的

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^weblog/archives/[0-9]{4}/[0-9]{2}/(.*)\.html$ https://newdomain.com/$1/ [R=301.L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

重新启动发动机
重写规则^weblog/archives/[0-9]{4}/[0-9]{2}/(.*)\.html$https://newdomain.com/$1/[R=301.L]
重写规则^index\.php$-[L]
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则/index.php[L]
如果将来有人需要它,它可以正常工作:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^weblog/archives/[0-9]{4}/[0-9]{2}/([^.]+)\.html$ http://www.newdomain.com/$1/ [L,R=301]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

重新启动发动机
重写规则^weblog/archives/[0-9]{4}/[0-9]{2}/([^.]+)\.html$http://www.newdomain.com/$1/[L,R=301]
重写规则^index\.php$-[L]
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则/index.php[L]

请发布您尝试过的内容。我删除了旧规则,但将尝试将我尝试过的解决方案组合在一起。现在将编辑我的问题。您的
重定向看起来正常,应该可以工作。它是否将您的旧url重定向到意外的位置?那么现在实际的旧url格式是什么?在底部添加的示例中,现在这个问题中有两种不同的URL格式。对于您最初说要重写的内容,
RewriteRule^weblog/archives/[0-9]{4}/[0-9]{2}/(.*)\.html$https://newdomain.com/$1/[R=301.L]
就可以了。
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^weblog/archives/[0-9]{4}/[0-9]{2}/([^.]+)\.html$ http://www.newdomain.com/$1/ [L,R=301]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>