htaccess URL redirection


htaccess URL redirection

如何将某些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

提前谢谢。

应该像:

RewriteEngine on 
RewriteRule ^mydir(.*)/(.*)/([a-z'-]{2,}([a-z'-]['d])['d])(.*)$ $2/$3$1-$4 [R=301,L]

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

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteRule ^mydir1/([^/]+)/(.+?)-('d+'.html)$ /$1/$2-1-$3 [L,R=301,NC]

您可以使用以下内容:

RewriteEngine On
RewriteRule ^/mydir2/(.*)+$ /mydir1/mydir2/$1

在你的htacces:中试试这个

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

注意:此代码未经过测试。

试试这个,

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

注意:代码未测试