My htacess rewrite is working but how to set redirection also - url-rewrite-module

I rewrite URL
https://myareanurse.com/?page=about-us
to
https://myareanurse.com/about-us
using below code
RewriteRule ^about-us/?$ index.php?page=about-us [NC,L]
Its working correct but when I open old URL that also open.
I need if I open old URL than its redirect to new URL.

Related

Redirect to another domain except for home page

I am trying to redirect my old website to a new domain with a few exceptions. These are the current rules that are in my .htaccess file and they are working great:
RewriteEngine on
# handle both specific URL redirects
RewriteRule ^/?product-(?:tag|categories)/([\w-]+) https://www.newdomain.com/parts?category=$1 [R=301,L,NC,QSA]
# redirect everything else
RewriteRule ^(.*)$ https://www.newdoamin.com/$1 [R=301,L,NE]
Now I want to add another rule. I want every page to be redirected to the new domain beside the home page on the old site. With that being said, I still want these exsiting rules to work if it is not the home page.
How can I add another redirect rule to my current htaccess that will not redirect when someone access the home page on the old domain and still apply my current rules?
I was trying to use this answer but I couldn't get my existing rules to work with it.
This should work:
RewriteEngine on
# handle both specific URL redirects
RewriteRule ^/?product-(?:tag|categories)/([\w-]+) https://www.newdomain.com/parts?category=$1 [R=301,L,NC,QSA]
# redirect everything else
RewriteRule ^/?(.+)$ https://www.newdoamin.com/$1 [R=301,L,NE]
.+ matches every URI except the home page. Make sure to clear your browser cache before testing.

.htaccess RewriteRule Redirect works on htaccess tester, does not work on server

I have an .htaccess file defined at www.mydomain/documentation/.htaccess and am trying to redirect a number of broken links to a specific page.
The .htaccess file contains the Rewrite Rule
RewriteRule ^/?(documentation/PresentationCore~System\.Windows\.RoutedEventArgs).*$
/documentation/v4.x/SciChart_WPF_v4_SDK_User_Manual.html [R,L,NC]
Note: RewriteEngine ON has already been defined. Other rules are being applied
Now in .htaccess tester the rule is being evaluated and redirects correctly when the following URL is requested:
www.mydomain.com/documentation/PresentationCore~System.Windows.RoutedEventArgs~Handled.html
However, when the same domain is entered into the browser, I get a 404 not found for this page.
I can confirm I have uploaded .htaccess to the correct folder and cleared the server cache.
Is there anything else I need to do to get this to work?
You dont need to match the folder name if htaccess is already in that folder, try :
RewriteRule ^/?(PresentationCore~System\.Windows\.RoutedEventArgs).*$
/documentation/v4.x/SciChart_WPF_v4_SDK_User_Manual.html [R,L,NC]

htaccess code to encode URLs with different page name

the below htaccess code work for single URL with same page
RewriteRule ^([^/]*)\.html$ /current/shoppe/sub-category.php?category=$1 [L]
now, i need to rewrite a URL of another page.

redirect old links (HTML site) to a new page (PHP site)

Recently I built a site with php but the old site they had was all in HTML. So now I dont know what what is the best way to redirect all those old links to the new site (maybe redirect all links with HTML to the main domain) with .htaccess, what is the best practice ?
Here is what I have tried but the site says to many redirect loops:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.de
RewriteRule (.*) http://www.example.de/$1 [R=301,L]
RedirectMatch "\.html$" http://www.example.de
So first we redirect all non-www links to www, then when the page has .html in the end to redirect to the main site.
Option 1: Redirect all old .htmllink to new sites's /
RewriteEngine On
RewriteRule \.html$ / [L,R=301,NC]
Option 2: If .html file name and .php file names are same then redirect all old .htmllink to new sites's .php /
RewriteEngine On
RewriteRule ^(.+?)\.html$ /$1.php [L,R=301,NC]
Depends, if it is a new domain you need to point to, add a domain pointer from the old domain to point towards the new domain, this will resolve in the server handling the redirect, this is the most efficient way.
This will work better than .htaccess because it's faster and does not cause a second initial page load (due to redirect).
If you don't have access to the server or domainpointers you could make the index.html an index.php file if php runs on the old server, from here simply put:
header('Location: http://www.newdomain.com/');
This will automatically redirect.
Hope this helped you.
‐ Sid

strip utm_source from url by htaccess then redirect to origin url

I have issues with URLs of website.
I have check the server and referrers, then see a lot of strange URLs with some addition var added to original. That may effect the SEO and server load to create those pages.
eg:
Original:
xaluan.com/modules.php?name=News&file=article&sid=123456
xaluan.com/modules.php?name=News&file=article&sid=123987
Someone access my web page by url
xaluan.com/modules.php?name=News&file=article&sid=123456&utm_source=twitterfeed&utm_medium=twitter
xaluan.com/modules.php?name=News&file=article&sid=123987&utm_source=twitterfeed&utm_medium=twitter
I need one .htaccess that can redirect all 301 URLs which have utm_source=twitterfeed&utm_medium=twitter to original one.
You could try this:
RewriteEngine on
RewriteCond %{QUERY_STRING} ^((.*?)&|)utm_
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1?%2 [R=301,NE,L]
It will drop everything from the Querystring after the first utm_.

Resources