I don't know much about .htaccess, but I'm trying to help a friend who recently moved his blog to Wordpress.
We need to redirect the OLD archive pages like this:
www.domain.com/2010_04_01_archive.html
www.domain.com/2010_04_02_archive.html
www.domain.com/2010_04_03_archive.html
to NEW archive pages like this:
www.domain.com/2010/04/01
www.domain.com/2010/04/02
www.domain.com/2010/04/03
I've tried everything I can find using htaccess redirect and rewrite, but again, I don't really know what I'm doing with htaccess!
Thanks so much for your help,
Amanda
OK tried this:
Turn mod_rewrite on
RewriteEngine On
RewriteRule ^([0-9]{4})([0-9]{2})([0-9]{2})_archive.html$ /$1/$2/$3 [L,R=301]
in .htaccess in the very top level folder of my site. Still, when I go to http://www.bikermetric.com/2010_04_01_archive.html, it doesn't redirect.
Just tried this too:
RedirectMatch 301 ^/([0-9]{4})([0-9]{2})([0-9]{2})_archive.html$ /$1/$2/$3
Still nothing.
You can use mod_alias or mod_rewrite here. You'll want to stick with using mod_rewrite if you already have rewrite rules (stuff that look like RewriteEngine or RewriteRule):
mod_alias:
RedirectMatch 301 ^/([0-9]{4})_([0-9]{2})_([0-9]{2})_archive.html$ /$1/$2/$3
mod_rewrite:
RewriteEngine On
RewriteRule ^([0-9]{4})_([0-9]{2})_([0-9]{2})_archive.html$ /$1/$2/$3 [L,R=301]
You'd want to add it to the htaccess file in your document root.
Related
I had to change the name of a subpage and now the problem is that all shared links on Facebook, Twitter, etc. are not working anymore.
That's why I am trying to redirect only a part of a URL with .htaccess but I have no solution yet.
It should work like this:
www.mydomain.com/feeds/details/ --> www.mydomain.com/highlights/details/
I hope you can help me!
It will depend on your server but you are looking for something along these lines
//Rewrite to www
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com[nc]
RewriteRule ^(.*)$ http://www.example.com/$1 [r=301,nc]
//301 Redirect Entire Directory
RedirectMatch 301 /feeds(.*) /highlights/$1
You can try rewriting the URL using RewriteRule, like follows:
.htaccess
RewriteEngine on
RewriteRule ^/feeds/details$ /highlights/details/
Hope, that works for you.
You can find more information here.
I took your tip and adjusted my reality.
My problem:
https://example.com/contact/example.com
My solution:
RedirectMatch 301 (.*)/example.com(.*) $1/$2
After solution, redirect:
https://example.com/contact/
I am migrating my site from Wordpress to Jekyll and I would like to keep the URLs working. My idea was to use a .htaccess file for this and to place it in the root of the site. But unfortunately after trying several tutorials and generates it doesn't seem to work.
The old URLs have the following format
http://example.com/index.php/2016/05/07/title-of-the-blog-post/
The new URLs have this format:
http://example.com/2016/05/07/title-of-the-blog-post.html
Among others I've tried this example which looks good to me, but it actually casues all pages on my site to display an error message :)
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^index.php.*$ http://example.com/ [R=301,L]
I think that should take all URLs that start with example.com/index.php and make them start with example.com/, but apparently that is not the case.
To redirect
http://example.com/index.php/2016/05/07/title-of-the-blog-post/
to
http://example.com/2016/05/07/title-of-the-blog-post.html
you can use the following rule :
RewriteEngine on
RewriteRule ^index\.php/(.+)$ http://example.com/$1.html [NE,L,R]
or alternatively you can use mod_alias like that:
RedirectMatch 301 ^/index\.php/(.+)$ http://example.com/$1.html
So i have this issue, with changing an old site with a new and I need to redirect all the old links. So have this:
domain.com/articles.php?var=1
I basicly want to redirect everything after articles.php to just domain.com, including the /articles.php.
Thank you in advance.
Try adding this to your htaccess file:
RedirectMatch 301 ^/articles\.php$ /
or if you have mod_rewrite rules already in your htaccess file, you need to use mod_rewrite isntead, and add this rule above whatever rules are already there:
RewriteRule ^articles\.php$ / [L,R=301]
I am doing a set of 301 redirects in Drupal.
I am using a standard method in the .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine on
Redirect 301 /user/testimonials http://thesitedomain.com/testimonials
Redirect 301 /user/contact http://thesitedomain.com/contact
</IfModule>
but the return url ends up with "?q=user" and stops it working. eg:
http://thesitedomain.com/about?q=user/about
I am not great at htaccess redirects (obviously) and I am no Drupal expert at all.
Also, if you know of a comprehensive htaccess rewrite resource I would much appreciate reading hat.
You will need to use mod_rewrite instead to strip out existing query string:
RewriteEngine On
RewriteRule ^user/testimonials/?$ http://thesitedomain.com/testimonials? [L,NC,R=301]
RewriteRule ^user/contact/?$ http://thesitedomain.com/contact? [L,NC,R=301]
Take note of trailing ? in target that strips out existing query string.
I can't speak to drupal, but I know you don't need to enclose those redirects in the <IfModule mod_rewrite.c> tags, since they don't use the RewriteEngine, the below would suffice:
Redirect 301 /user/testimonials http://thesitedomain.com/testimonials
Redirect 301 /user/contact http://thesitedomain.com/contact
Are both urls in the same drupal? Or are you moving from a different site?
I mean:
/user/testimonials
http://thesitedomain.com/testimonials
Maybe what you need is to add an url alias for /user/testimonials like /testimonials
See under admin at /admin/config/search/path in drupal 7.
Using .htaccess file is not a good practice, because, in some updates you have to update the .htaccess file too.
You can try GlobalRedirect module to manage your redirects.
I am creating htaccess for my site I need to redirect old urls to new url through 301 redirect. I have created code in htaccess as follows
My old urls like
www.example.com/categories/city/cityname/brandname/product1.html
and my new url is like
www.example.com/product1.html
For this scenario I have written following code in htaccess
RedirectMatch 301 ^/categories/city/cityname/(.*)$ http://www.example.com/$1
Please help me regarding this scenario or where I am doing wrong.
Try using mod_rewrite's functionality in your .htaccess like this:
RewriteEngine On
RewriteRule ^/categories/city/cityname/(.*)$ /$1 [R=301,L]
Referring to #Seybsen answer, this 1 line should fit all your needs :
RewriteRule ^/([a-zA-Z]+)/([a-zA-Z]+)/([a-zA-Z]+)/([a-zA-Z]+)/(.*)$ /$5 [R=301,L]