1

How can i redirect some URLs to different format.

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

I want to redirect the above URLs to below format.

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

Thanks in advance.

2
  • 2
    Find a basic htaccess tutorial online? This doesn't look complex at all... What have you attempted? Commented Aug 1, 2013 at 6:36
  • I have made some changes in my question and i couldn't find the solution in any tutorial. Commented Aug 1, 2013 at 7:10

5 Answers 5

1

Should be like:

RewriteEngine on 
RewriteRule ^mydir(.*)/(.*)/([a-z\-]{2,}([a-z\-][\d])[\d])(.*)$ $2/$3$1-$4 [R=301,L]
Sign up to request clarification or add additional context in comments.

5 Comments

Thanks. I cannot use the word 'my-article' in rule, because, it will be different in all URLS. Please see the new changes in question.
Thanks for the reply, but it is not working, it is not adding '-1' in url before the number. i.e my-article-first-86974.html should change to my-article-first-1-86974.html, it is not happening.
I tried the latest rule which you have given, but it is not making any change in URL.
URL redirecting without 1? Like: my-article-first-86974.html?
@Saritha It have to work. Updated again. Redirecting where now?
0

Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On

RewriteRule ^mydir1/([^/]+)/(.+?)-(\d+\.html)$ /$1/$2-1-$3 [L,R=301,NC]

3 Comments

Thanks. I cannot use the word 'my-article' and 'mydir2' in rule, because it will be different in all URLS. Please see the new changes in question.
Thanks for the reply. I tried this but it is not adding '-1' in url before the number. i.e my-article-first-86974.html should change to my-article-first-1-86974.html.
Ah I overlooked that -1 requirement, sorry editing it again.
0

You can use something along these lines:

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

2 Comments

redirecting my-article-1
Thanks, i have made some changes in my question.
0

Try this in your htacces :

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

Note : this code is not tested.

Comments

0

try this,

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

you can see this RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]

NOTE:CODE NOT TESTED

2 Comments

Thanks. I cannot use the word 'my-article' and 'mydir2' in rule, because it will be different in all URLS. Please see the new changes in question.
Thanks, I tried your answer, it is affecting all the URLs in my project, i just want to redirect URLs starts with mysite.com/mydir1.......

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.