1

如何将某些 URL 重定向到不同的格式。

http://mysite.com/mydir1/mydir2/my-article-first-86974.html
http://mysite.com/mydir1/somefolder/my-article-76674.html
http://mysite.com/mydir1/anotherfolder/some-text-35667.html
http://mysite.com/mydir1/mydir6/my-article-another-75445.html

我想将上述 URL 重定向到以下格式。

http://mysite.com/mydir2/my-article-first-1-86974.html
http://mysite.com/somefolder/my-article-1-76674.html
http://mysite.com/anotherfolder/some-text-1-35667.html
http://mysite.com/mydir6/my-article-another-1-75445.html

提前致谢。

4

5 回答 5

1

应该是这样的:

RewriteEngine on 
RewriteRule ^mydir(.*)/(.*)/([a-z\-]{2,}([a-z\-][\d])[\d])(.*)$ $2/$3$1-$4 [R=301,L]
于 2013-08-01T06:38:29.833 回答
0

您可以使用以下内容:

RewriteEngine On
RewriteRule ^/mydir2/(.*)+$ /mydir1/mydir2/$1
于 2013-08-01T06:38:49.077 回答
0

在你的 htacces 中试试这个:

<IfModule mod_rewrite.c>
        RewriteEngine   On
        RewriteBase http://mysite.com 
        RewriteRule     ^/(.+)$ /mydir1/mydir2/$1 [L]
</IfModule>

注意:此代码未经测试。

于 2013-08-01T06:39:36.880 回答
0

尝试这个,

    # SEO URL Settings
    RewriteEngine On
    # If your installation does not run on the main web folder make sure you folder it does run in ie. / becomes /shop/ 

    RewriteBase /
    RewriteRule ^sitemap.xml$ index.php?route=feed/google_sitemap [L]
    RewriteRule ^googlebase.xml$ index.php?route=feed/google_base [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css)
    RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]

你可以看到这个 RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]

注意:代码未测试

于 2013-08-01T06:40:51.520 回答
0

通过启用 mod_rewrite 和 .htaccess httpd.conf,然后将此代码放在您.htaccessDOCUMENT_ROOT目录下:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On

RewriteRule ^mydir1/([^/]+)/(.+?)-(\d+\.html)$ /$1/$2-1-$3 [L,R=301,NC]
于 2013-08-01T06:43:10.450 回答