htaccess for URLS - apache

Can anyone let me know how i can redirect all urls so they include a new path.
For example, on my old site i have a urls like this:
http://www.example.com/tag/tag-title1/
http://www.example.com/tag/tag-title2/
http://www.example.com/tag/tag-title3/
I now need all of these to be redirected to:
http://www.example.com/waterblog/tag/tag-title1
http://www.example.com/waterblog/tag/tag-title2
http://www.example.com/waterblog/tag/tag-title3
So really all i need to do is add /waterblog/ before the /tag/ on all URLS.
Thanks

You can use this .htaccess:
RewriteEngine on
RewriteRule ^((?!waterblog/).*)$ waterblog/$1 [NC,R,L]

So really all i need to do is add /waterblog/ before the /tag/ on all URLS.
You can use this simple rule in your root .htaccess:
RedirectMatch 302 ^/(tag/.*)$ /waterblog/$1

Related

RedirectMatch adding extra url segments

I'm trying to redirect requests for our old blog to a new url on a subdomain.
The old url looks like
https://www.website.com/blog-name/post/slug-of-the-title
and it needs to redirect to
https://stage.website.com/blog-name/slug-of-the-title
I'm using this rule in my .htaccess
RedirectMatch ^/blog-name/post/(.*)$ https://stage.website.com/blog-name/$1
And I'm getting redirected to the correct page, but my urls have extra segments on the end. Like
https://stage.website.com/blog-name/slug-of-the-title/?/blog-name/post/slug-of-the-title
What am I doing wrong?
With your shown samples, could you please try following. Please clear your browser cache before testing your URLs. Make sure you keep these rules at the top of your .htaccess rules file(in case you have any more rules also in your .htaccess file).
RewriteEngine ON
RewriteCond %{HTTP_HOST} ^(?:www\.)?website\.com$ [NC]
RewriteRule ^blog-name/post/(.*)/?$ https://stage.website.com/blog-name/$1? [NC,R=301,L]

Apache 301 bulk redirect

Is there a way to redirect all link with certain path? For example:
mydomain.com/free-products/product1
mydomain.com/free-products/product2
mydomain.com/free-products/productn
become:
mydomain.com/free/product1
mydomain.com/free/product2
mydomain.com/free/productn
I prefer to redirect using apache vhost instead of htaccess
Thanks for the clues..
Appreciated..
This should work
RewriteEngine on
RewriteRule ^free-products/product([0-9]+)$ /free/product$1 [R=301,L]
There is no matter where to place it, inside vhost or htaccess.
You can also use RedirectMatch.
RedirectMatch permanent ^/free-products/(.*) mydomain.com/free/$1
See http://httpd.apache.org/docs/2.2/mod/mod_alias.html for more information regarding mod_alias.

.htaccess 301 permanent redirect rule

I have this url structure right now.
http://example.com/weather/in-city_name
which I want to permanently redirect to
http://example.com/city_name/weather
Here is what I'm writing to the .htaccess file using this reference
RedirectMatch ^/weather/(.*)$ http://example.com/$1/weather
But this doesn't work.
In my condition city_name is dynamic and manual entry is not possible.
Any suggestion about how to achieve the desire result would be great.
You can use this .htaccess:
RewriteEngine on
RewriteRule ^weather/in-(.+)/?$ /$1/weather [R=301,NC,L]

How to redirect my URLs using htaccess 301 conditional

I need help redirecting my old URL to a new URL.
They URLS are structured as required.
My OLD URL is something like domain.com/category/123-title-of-article.html, where category is the category name and 123 is the Post ID
The NEW URLs are (and this is how I want them to redirect): domain.com/article/title-of-article-123/, where article will remain as it is in all URLS, and the post ID will go to end of the URL
How I can achieve this?
This should work for you:
RewriteEngine On
RewriteRule ^(.*)/([0-9]+)-(.*).html$ /article/$3-$2/ [R=301,L]
It should change domain.com/category/123-title-of-article.html to domain.com/article/title-of-article-123/
RewriteEngine On
RewriteRule ^/?category/(\d+)-(.+)\.html$ /article/$2-$1/ [L,R=301]
Also, you already have the rewrite rules to handle your new URL, right?

Redirect complete url to another url

Actually i have changed my dynamic urls to static urls. But the strange thing is i have some old urls which are dynamic. Among them the url is http://www.startonlinegames.com/download.php . I want this url to redirect to http://www.startonlinegames.com/download/?page=download .. for this i have added the following htaccess rule in my htaccess file.
Redirect http://www.startonlinegames.com/download.php http://www.startonlinegames.com/download/?page=download
but its not working...can anyone suggest me.
Try this : and let me know if it works otherwise will try for another
Options +FollowSymlinks
RewriteEngine on
rewriterule ^download.php(.*)$ http://www.startonlinegames.com/download/?page=download$1 [r=301,nc]