Htaccess重定向通配符

时间:2014-01-06 18:10:26

标签: apache .htaccess mod-rewrite redirect http-status-code-301

我们最近将我们的网站转移到了一个新的CMS,但我仍然无法重定向一个目录。

我们的旧网址结构如下:

/目录/子目录/这-是最后/ 81281 /

我想将其重定向到:

/这-是最后的81281

当前.htaccess文件

# 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]
</IfModule>

RewriteEngine On
RewriteRule ^[^/]+/[^/]+/([^/]+)/([0-9]+)/?$ /$1-$2 [L,R]

#Redirected wildcard /new to forward slash.
 RedirectMatch 301 /new/(.*) /$1

2 个答案:

答案 0 :(得分:0)

将此代码放入DOCUMENT_ROOT/.htaccess文件中:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteRule ^[^/]+/[^/]+/([^/]+)/([0-9]+)/?$ /$1-$2 [L,R]

RewriteRule ^new/(.*)$ /$1 [L,R]

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

答案 1 :(得分:0)

我在.htaccess重定向中所做的事情

Redirect permanent /directory/sub-directory/this-is-the-post/81281 http://www.youdomain.com/this-is-the-post-81281