301 Redirect Dynamic to new URL - .htaccess

i want to redirect (301) my (old) URLs/Links with mod_rewrite. But i donĀ“t know the rules i have to use in the htaccess.
My URL is one like this
https://www.pausenhof.de/referat/physik/magnetismus/14619
and now i want to move it to
https://www.pausenhof.de/referat/physik-magnetismus-14619
how is the 301 rule for redirect for google?
this here are dynmaic
https://www.pausenhof.de/referat/physik/magnetismus/14619
many thanks

i have found it. this rule work
RewriteRule ^referat/([a-zA-Z0-9.+-]+)/([a-zA-Z0-9.+-]+)/([0-9]+)$ referat/$1-$2-$3 [L,R=301]

Related

How to implement 301 permanent redirection using htaccess with custom parameter in URL?

Here I have a URL like www.abc.com/product/women/casual/page:5/ and I need to implement 301 permanent redirection using htaccess in order to change the URL to www.abc.com/product/women/casual/page/5/. In this case, parameter women and casual is customized category and subcategory and page:5 is page number 5. I need to change the last parameter page:5 to page/5 using htaccess 301 permanent redirection. Can anyone please help me to find a solution for the case.
You can use the following redirect :
RedirectMatch 301 ^/([^:]+):5/$ /$1/5/
Or a more generic one:
RedirectMatch 301 ^/([^:]+):([0-9])/?$ /$1/$2
This will redirect your old URL to the new one , for example example.com/foo/bar:digit/ to example.com/foo/bar/digit/ .
Or you can use RewriteRule directive
RewriteEngine on
RewriteRule ^([^:]+):5/$ /$1/5/ [R=301,L]

How to redirect multiple URLs dynamically with htaccess?

How can I redirect each link/URL like https://example.com/blogspot/good-url to https://example.com/blog/good-url
In all links I just want to replace blogspot with blog Is this something we can achieve through .htaccess?
RedirectMatch 302 ^/blogspot/$ https://example.com/blog/$
also tried the below but doesn't seems to work:
RewriteRule ^/?blogspot/(.*)$ https://example.com/blog/$1 [R=301,L]
You can a simple Redirect for this
Redirect 302 /blogspot/ https://example.com/blog/
This will redirect all URLs from /blogspot/foobar to /blog/foobar .

How to 301 redirect old website to a new one

I would like to 301 redirect my old domain say m.oldwebsite.com to m.newwebsite.com.
I believe the line below will redirect and keep the url path.
RewriteRule ^(.*)$ https://m.newwebsite.com/$1 [L,R=301]
What I need is for all links on m.oldwebsite.com to redirect to the home page of m.newwebsite.com.
Forexample:
m.oldwebsite.com/path/to
to redirect to
m.oldwebsite.com
I couldn't find a clear solution for this.
Thanks!
Remove $1 parameter from rewrite and it's done, all redirect to homepage.

How to do 301 redirects with folders & subfolders?

I need to redirect all the old URLs on my site to new URLs, but am having issues. A given URL and its subfolders need redirecting to the same page.
For example, this is the first one:
redirect 301 /panache/sports-bra/ http://www.newdomain.co.uk/sports-bra.html
This works ok. However there are these size sub-pages which need to redirect to the same location:
redirect 301 /panache/sports-bra/30DD http://www.newdomain.co.uk/sports-bra.html
redirect 301 /panache/sports-bra/30E http://www.newdomain.co.uk/sports-bra.html
redirect 301 /panache/sports-bra/30F http://www.newdomain.co.uk/sports-bra.html
And these don't work, I end up at a location like the following:
http://www.newdomain.co.uk/sports-bra.html30DD
See the way the last part of the path is appended to the url? I'm guessing it's because the second redirect is conflicting with the initial 301 redirect?
I have also tried using this rewrite rule but have had no luck. The site is Magento so I don't know if this has some effect? mod_rewrite is enabled on the server.
RewriteRule ^panache/sports-bra/ http://www.newdomain.co.uk/sports-bra.html [R=301]
Any help mucha ppreciated.
Try this.
RewriteEngine on
RewriteRule ^(panache/sports-bra/.*)$ /sports-bra.html [L,R=301,NC]

301 redirect urls

I'm trying to redirect an old url to a new one using 301
I need an example of RewriteQueryString for the following 301? http://www .example.com/search/?depId=1&typeCatId=1 to the following http://www.example.com/mens/clothing
So when I type in the long URL in the browser, I am redirected to the new, shorter URL
Any ideas?
RewriteEngine On
RewriteRule ^search/\?depId=1&typeCatId=1$ /mens/clothing [R=301]
^ Try that.
You could use mod_rewrite either in your .htaccess file or the apache configuration. You might take a look at the RewriteMap feature if you are going to have a lot of different departments, etc. to map. Using the [R] flag after the RewriteRule will cause the browser to redirect instead of just being an internal redirect. Using [R=301] will make it a 301 redirect.

Resources