Why http://www. goes to /index.php and https://www. does not? - apache

I'm running into a strange error causing poor SEO results.
Everything works expect when using http://www. it shows /index.php
but, https://www. or http:// or https:// does not show index.php
This is my rewrite conf
RewriteCond %{HTTP_HOST} ^www\.domain\.com$
RewriteRule ^/?$ "https\:\/\/domain\.com\" [R=301,L]

If you have search console you could check what is wrong with your domain.If you couldn`t find any problem my advice is to find good SEO agency. http://www.asknatewang.com/ There is a chance your ranking to be affected because of the discrepancy.
Greetings!

Related

Htaccess 301 redirect with variables

I am having some problems. I switched over from one e-commerce system to another a while back and this changed the url structure of some of the pages. I was fine with this and set up some rewrite rules. Somehow this has stopped working and I am not sure why.
I need to change
/product/{Category-Name}/{URL} to /{URL}
/ecategory/{Category-ID}/{URL} to /{URL}
/manu/{URL} to /{URL}
/news/{category-name}/{URL} to /blog/{URL}
I am using
RewriteRule ^/?(product|ecategory)/([^\/]+)/(.+?)\$ /$3 [R=301,L]
RewriteRule ^/?(manu)/(.+?)\$ /$2 [R=301,L]
RewriteRule ^/?(news)/([^\/]+)/(.+?)\$ /blog/$2/$3 [R=301,L]
RewriteRule ^/?(newscategory)/([^\/]+)/(.+?)\$ /blog/$3 [R=301,L]
RewriteRule ^/?([0-9]+)/(.+?)\$ /$2 [R=301,L]
Bu this is not working now and I don't have enough knowledge of htaccess redirects to work out what is wrong. I have been making changes and looking online but I feel like I am going in circles and this is very confusing.
Please, can anyone give me some advice?
I solved it by removing the / before the $. This was my mistake from when I think the URLs used to have .html at the end.

.htaccess redirect to another domain except admin page

I am asking because I can not for the live of me figure out what is wrong and so far none of the StackOverflow answers worked.
I have to redirect a domain to another subdomain, except the admin. For example:
sub1.domain.com/testsite/ shoud redirect to "sub2.domain.com/testsite/",
but sub1.domain.com/admin/ or "sub1.domain.com/de/admin/" should stay right where it is.
As a first step I tried to only check for the "admin", so everything would be redirected except "sub1.domain.com/admin/":
RewriteCond %{HTTP_HOST} ^sub1\.domain\.com
RewriteCond %{REQUEST_URI} !^\/admin
RewriteRule ^/?(.*)$ http\:\/\/sub2\.domain\.com%{REQUEST_URI} [R=301,L]
This one looked most promising, but it is not working. The second condition is not working and the admin page still gets redirected.
If anyone can help I would appreciate it.
EDIT:
I should have said that its a multi-domain site, which means we have a .htaccess file for all sites and that is the reason I specifically check for the domain.
I'm just posting this, but I can't test it!
But I guess this redirects EVERYTHING except that one domain.
RewriteCond %{HTTP_HOST} !^sub1.domain.com/admin/ [NC]
RewriteRule ^/(.*)$http\:\/\/sub2\.domain\.com%{REQUEST_URI} [R=301,L,NC]
I hope it works!
So,
I just found the reason (besides my stupidity). The site I should redirect was a Drupal Site. Thats why all links end up at the same location:
sub1.domain.com/index.php
The reason why my above Rewrite Condition was not working is, that sub1.domain.com/admin is being redirected to sub1.domain.com/index.php, which consequently ends up at: "sub2.domain.com/index.php". The correct rewrite rule looks like that:
RewriteCond %{HTTP_HOST} ^sub1\.domain\.com
RewriteCond %{REQUEST_URI} !^/(admin|index\.php|de\/admin|it\/admin|user|de\/user|it\/user)
RewriteRule (.*) http://sub2.domain.com%{REQUEST_URI} [R=301,L]
This redirects everything except:
sub1.domain.com/admin
sub1.domain.com/de/admin
sub1.domain.com/it/admin
sub1.domain.com/user
sub1.domain.com/de/user
sub1.domain.com/it/user
and of course
sub1.domain.com/index.php
Since the last one also should not be redirected if the user types it in directly, it is not a perfect solution, but I can live with it.
RewriteCond is use to check condition weather to execute .htacess or not
For your case the solution may be as below:-
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain\.com [NC]
RewriteRule ^(admin)$ http://sub1.domain.com/$1 [R=301,L]
RewriteRule ^(.*)$ http://sub2.domain.com/$1 [R=301,L]

How To Remove Redundent ?p=1 From URL

So I had an issue where my pagination would append a ?p=1 to the end of a URL when moving from page 2 back to page 1. With the issue corrected so those links no longer get served, I do have to try and find a way to do a 301 redirect from those URLs to the proper URL so that the search engines can update those links.
I am on an Apache server, and I would like to be able to use RedirectMatch 301 to do this, however I do not think that it plays well with query strings.
RedirectMatch 301 (.*)?p=1 http://mydomain.com/$1
does not do the trick
I believe the solution is going to end up being that I use RedirectCond and Rewrite statements to make this work, however I do not know how to get this to redirect.
Can someone help me out with this? What I have so far gives me Internal Server Errors so obviously I am not on the right track yet.
RewriteCond %{REQUEST_URI} (.*)$
RewriteCond %{QUERY_STRING} ^?p=1$
RewriteRule ^.*$ http://devserver/$1 [L,R=301]
If someone can even point me toward a good tutorial on how to set this up would be helpful too.
RewriteCond %{QUERY_STRING} (^|&)p=1(&|$)
RewriteRule . http://devserver%{REQUEST_URI}? [L,R=301]

Replace one URL with another by using mod_rewrite

Current situation
RewriteRule ^$ /index.php?page=Portal [R=301,L]
When a user comes to the website and goes to the "root" url of the domain (RegExp "^$") he's redirected to /index.php?page=Portal
That's working.
Now we have "index.php?page=Portal" in the google index and we have tons of links to that page on various locations all over the internet.
Intended new situation
We want the portal page to show up on the root url - no redirect. That's no problem... Just remove the redirect:
RewriteRule ^$ /index.php?page=Portal [L]
Now we also want the old url to redirect to the new location, and that's where I fail but can't see why:
RewriteCond %{QUERY_STRING} ^page=Portal$
RewriteRule ^index.php$ http://www.jacatu.de/? [R=301,L]
As soon as I do this I end up in a redirect loop:
(When I change to 302 in .htaccess I see 302 redirects, so the loop really seems to be caused by mod_rewrite)
But why? All rules are marked as last [L] - so I think I can rule out that rule 2 triggers rule 1.
I enabled logging as suggested by Jacek Prucia and in fact it looked like having [L] in the URL doesn't stop execution. Both rules were processed.
I now changed the first rewrite to
RewriteRule ^$ /index.php?page=Portal&int=1 [L]
so that it doesn't match the RewriteCond of the internal rewrite so theoretically my problem is solved. It would be nice to know, though, why it did what it did. :)

mod_rewrite rewriting a url

Hay, can someone lend a helping hand to get a rewrite rule to work?
I'm developing a CMS and the URL currently look like this
page.php?id=2/About-us
I want to remove the
page.php?id=2/
part of the URL and just show
About-us
Any ideas how to get this working?
EDIT
I have since changed my URLS to
page/PAGE_NAME
and used the rule
RewriteRule ^page/([^/\.]+)/?$ index.php?page=$1 [L]
However, apache just says that index.php was not found on the server.
Are you sure it is index.php and not page.php?
Please try
RewriteRule ^/page/([^/]+)$ /index.php?page=$1 [L]
If you need a permanent move
RewriteRule ^/page/([^/]+)$ /index.php?page=$1 [R=301,L]