htaccess to remove trailing /login from URL - .htaccess

For some reason Googlebot are crawling URLs with a "/login" at the end.
I'm trying to remove this trailing /login , 301 redirect with htaccess.
domain.com/login - this URL exists
but these do not :
domain.com/*/login domain.com.au/*/*/login domain.com.au/*/*/*/login
etc
Following is htaccess rules tried:
RewriteEngine ON
RewriteRule (.*)/login$ /$1 [L,R=301]

Please try following htaccess rules. Please make sure to clear your browser cache before testing your URLs. As per description, this will redirect all urls which are ending with login and NOT starting from login.
RewriteEngine ON
RewriteRule ^(.*)/login/?$ $1 [R=301,NC,L]

Related

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.

htaccess redirect some partical url 301 SEO

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 .

301 redirect parameters without index.php in HTACCESS

After reading not too few threds in here and testing, I still haven't found a solution for some messy URL's I want to redirect.
Example 1:
I want to redirect the following URL:
www.mysite.co.il/binyanei/minisite/?ref=glob_AdvertisingArticle
to
www.mysite.co.il/
I found this syntax, but it's only relevant for URL's with index.php and it's just doesn't work for me:
RewriteEngine on
RewriteCond %{QUERY_STRING} id=1
RewriteRule ^sub-dir/index\.php$ /path-to-new-location/? [L,R=301]
Redirect one clean URL to a new clean URL

URL Rewriting in. Htaccess

I have a website on a test server and I want to rewrite URL for this website because it is very long
I wish our visitors instead of entering this URL:
http://staging.company.fr/site2.it/s...oject2/public/
enter this URL:
www.monsite.com
I created a file. htaccess:
RewriteEngine On
RewriteRule ^/~(.+) http://www.monsite.com/~$1 [NC,L]
but does not work
While in .htaccess mod_rewrite doesn't match leading slash in a URL since it is applied per directory. Therefore following should work:
RewriteEngine On
RewriteRule ^(.+)$ http://www.monsite.com/$1 [L,R=301,NE]
This will redirect every URL in your existing domain other than home / to monsite.com
Reference: Apache mod_rewrite Introduction

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