htaccess redirect some partical url 301 SEO - .htaccess

something on our BLOG URLS have changed.
No i want to have some URL path deleted in urls.
Example:
OLD URL:
https://do-main.de/blog/entry/die-xxx-der-portrait
NEW URL:
https://do-main.de/blog/die-xxx-der-portrait
My htaccess attempt to setup:
#OLD BLOG URLS
RewriteEngine On
# anything that is equal to https://do-main.de/blog/entry/*
RewriteCond %{HTTP_HOST} ^do\-main\.de\/blog\/entry\/$
# redirects to https://do-main.de/blog/*
RewriteRule ^/?(.*)$ https://do-main.de/blog/$1 [R=301,L]
conclusion all URLS with "entry" should be only using /blog/ without /entry/
Do you understand? Can anyone help?

You can use Redirect directive.
Redirect 301 /blog/entry/ http://example.com/blog/
This will 301 redirect all requests from example.com/blog/entry/foobar to http:// example.com/blog/foobar .

Related

Redirect all pages containing a particular part to home using htaccess

Recently my site got hacked, and tons of pages were generated. Most of them end with strings like ?_t=77, ?_t=97, and ?_t=56 etc. Basically, the ?_t= part is common in all of them.
How do I create a .htaccess rule to redirect all the links with ?_t= to home?
Some redirects I've already created:
<IfModule mod_rewrite.c>
RewriteEngine On
Redirect 301 /profile/1320172681 /u/DanLiu
Redirect 301 /profile/387899125 /u/LuckyMaheshwari
Redirect 301 /profile/15379797 /u/manishchopra
Redirect 301 /profile/335596945 /u/MatthewNord
Redirect 301 /profile/94097446 /u/abhimanyu
</IfModule>
Thanks
With your shown attempts/samples, please try following htaccess rules. Please make sure to clear your browser cache before testing your URLs.
<IfModule mod_rewrite.c>
##making your Rewrite engine ON here.
RewriteEngine On
##Rewriting urls with ending with ?_t=digits to home page here.
RewriteCond %{QUERY_STRING} ^_t=\d+/?$ [NC]
RewriteRule ^ / [R=301,L,QSD]
##Rewriting home page url to index.php here.
RewriteRule ^/?$ index.php [QSA,L]
###put your rest of htaccess Rules from here onwards.
Redirect 301 /profile/1320172681 /u/DanLiu
Redirect 301 /profile/387899125 /u/LuckyMaheshwari
Redirect 301 /profile/15379797 /u/manishchopra
Redirect 301 /profile/335596945 /u/MatthewNord
Redirect 301 /profile/94097446 /u/abhimanyu
</IfModule>

How to redirect all subdomain URL to main domain using htaccess?

My old blog URL is http://www.blog.example.com/
My new blog URL is https://example.com/
I want to know how can I redirect all my old blog URLs to my new blog URLs.
For example, I want to redirect this URL:
http://www.blog.example.com/excellent-examples-forms-web-design
to
https://example.com/excellent-examples-forms-web-design
You can do this using mod_rewrite in .htaccess. mod_rewrite is required in order to check the requested hostname.
For example, at the top of your .htaccess file:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.blog\.(example\.com) [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [R=301,L]
The %1 backreference matches example.com in the preceding CondPattern (this simply saves repetition).
Test first with a 302 (temporary) redirect and change to a 301 (permanent) redirect when you are sure it's working OK - to avoid potential caching issues.

Can't use ? when redirect 301 with .htaccess

I have a website which is being renewed.
It has url's like site.com/page.php?p=company&l=nl
The new URL is site.com/company
I would like to use .htaccess to redirect 301.
(I would like to keep the SEO pagerank for the old pages)
Because of the ? it doesn't work.
This is the rule I use in my htaccess which doesn't work:
Redirect 301 /page.php?p=company&l=nl http ://www.site.com/company
This is the rule I use in my htaccess which does work:
Redirect 301 /page.php http ://www.site.com/company
I need the ?p=...
This should work:
RewriteCond %{QUERY_STRING} ^p=company&l=nl$ [NC]
RewriteRule ^page\.php$ http ://www.site.com/company? [R=301,NE,NC,L]
Remove the space between http and :

How can I redirect URL's with numbers using by htaccess?

I need redircet a lot of pages on my site.
all those page url is:
/index.php?act=download&id=9&mirror=0
/index.php?act=download&id=9&mirror=1
/index.php?act=download&id=9&mirror=2
/index.php?act=download&id=10&mirror=0
/index.php?act=download&id=10&mirror=1
Etc.
I need to write in my htaccess file this code:
Redirect 301 /index.php?act=download&id=9&mirror=0 http://mydomain.com
Redirect 301 /index.php?act=download&id=9&mirror=1 http://mydomain.com
Redirect 301 /index.php?act=download&id=9&mirror=2 http://mydomain.com
Redirect 301 /index.php?act=download&id=10&mirror=0 http://mydomain.com
Redirect 301 /index.php?act=download&id=10&mirror=1 http://mydomain.com
Redirect 301 /index.php?act=download&id=10&mirror=2 http://mydomain.com
but I have a lot more..
how can I redirect all of this:
/index.phpact=download&id=ANY-NUMBER&mirror=ANY-NUMBER
to my main page? (http://mydomain.com)
You cant match query string using Redirect directive. Use mod_rewrite instead:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^act=download&id=[0-9]+&mirror=[0-9]+
RewriteRule ^index\.php$ http://mydomain.com? [L,R=301,NC]

301 redirect after url rewrite

I did some htaccess URL rewrite. To keep my google ranking I must redirect the old URL to the new one; the problem is the old URL still 'exist' and I'm not sure how to do the redirect. This is an example:
old url: mypage.php?id=myId
which now is rewritten as: mypage-myId.html
this is the htaccess directive
RewriteRule ^mypage-([A-Za-z0-9_-]+).html$ mypage.php?id=$1 [L]
now I want to 301 redirect all the old url (mypage.php?id=myIds) to the new url (mypage-myIds.html).
I tried this at the top of my htaccess file:
redirect 301 mypage.php?id=1 to mypage-1.html
but nothing happens, the page stays on mypage.php?id=1.
What's wrong with this? I found another post about this problem
url rewrite & redirect question
but the solution wasn't that clear to me.
Thanks in advance
Vittorio
You could try this:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^id=([A-Za-z0-9_-]+)$ # fetch ID
RewriteRule ^mypage\.php$ http://domain.com/mypage-%1.html [R=301,L] # redirect old URL to new
RewriteRule ^mypage-([A-Za-z0-9_-]+)\.html$ mypage.php?id=$1 [L] # rewrite

Resources