.htaccess和正则表达式删除部分uri

时间:2017-10-12 16:24:55

标签: wordpress .htaccess

我想像这样重定向路径

http://www.example.com/uploads/2017/10/image.ext/version/?id=87988984632

http://www.example.com/uploads/2017/10/image.ext

其中扩展名可以是任何图片或视频扩展名。 我可以用\/version\/(.*)$检测到最后一部分,但我无法从uri中删除。

更新

这是我的.htaccess,我正在使用Wordpress

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteRule \/version\/(.*)$ 
</IfModule>

感谢您的帮助

1 个答案:

答案 0 :(得分:1)

您可以在其他WP规则之前使用此新重定向:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteRule ^(.+)/version/?$ /$1? [L,NC,NE,R=301]

RewriteRule ^index\.php$ - [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>