I'm currently using this rule to redirect traffic (except one url) to a new url.
It works fine when using a non www url like "subdomain.olddomain.com" but when accessing it with www like "www.subdomain.olddomain.com", I get a redirection error. This is the rule i use:
RewriteCond %{REQUEST_URI} !^/exception($|/)
RewriteRule ^(.*)$ https://www.newdomain.com/ [R=301,L]
What am I missing here? I'm not an expert in any way with htaccess… Thank you!
PS: I already searched for answeres but couldn't find any matching my subdomain issue.
Seems like I had to change some domain settings, the rule above works as expected.
Related
I have a web with 3 domains. com, .de, .co.uk. One domain for one language.
By now the languages are in .com and it runs like this:
www.domain.com/?lang=de
www.domain.com/?lang=en
www.domain.com/?lang=fr
But now I need the web not accessible with www.domain.com/?lang=en and automaticaly redirect to www.domain.co.uk
I've tryed with:
RewriteEngine On
RedirectMatch de$ http://www.domain.de
But don't works for me.
Anyone knows how can I do this?
Thank you very match in advance.
You should use the QUERY_STRING Rewrite-Condition to check for query parameters. e.g.:
RewriteCond %{QUERY_STRING} ^lang=de$
RewriteRule ^/$ http://www.domain.de [R,L]
Assume I have two domain names example1.com and example2.com. I forwarded example1.com to example2.com using the domain forwarding on hosting panel. It works fine but when I go to example1.com/sub it just shows example2.com as the URL. I want it to show example2.com/sub. I tried URL rewriting but no luck so far. It just keep loading and shows nothing. Am I missing something ?
This the rule I used.
RewriteEngine On
RewriteCond %{HTTP_HOST} !^example1.com$ [NC]
RewriteRule (.*) http://www.example2.com/$1 [R=301]
First make sure that you've cleared your browser's cache. If it's a 301 redirect your browser will cache the redirect. Then make sure to turn off your hosting panel's forwarding.
Other than that, your rule should work fine, assuming it's at the top of the htaccess file in example1.com's document root.
In RewriteCond rule you use !, which mean negate the result of the condition.
I am trying to add www prefix to my domain. My domain is developigner.com.
I have used this code in .htaccess file but still am not able to get the desired result.
Here's my .htaccess file
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{http_host} ^developigner.com [nc]
RewriteRule ^(.*)$ http://www.developigner.com/$1 [R=301,nc,L]
The problem is that if I type developigner.com it gets redirected to www.your_domain.com and if I type www.developigner.com it works perfectly.
I want your_domain to be replaced by developigner
Any help would be greatly appreciated.
Thanks
It works for me as expected: developigner.com redirects to www.developigner.com.
I notice you only registered the domain yesterday. It's possible this problem is actually caused by delays in the global propagation of your domain name.
I have created a website using IPB which I believe is written in PHP.
i am trying to use a 301 prominent redirect but when ever I try to use any from around the web I get a 500 server error
the broken url is 'http://thereviewforum.com/index.php?/page/index.html/_/monthly-top-10/top-10-free-vpn-service-providers-r17'
and I would like to direct users and search bots to
http://thereviewforum.com/monthly_top_10.html/_/monthly-top-10/top-10-free-vpn-service-providers-r17
again any help with be greatly appreciated!
I think you can do (The following does not work. See below for working example):
Redirect 301 /index.php?/page/index.html/_/monthly-top-10/top-10-free-vpn-service-providers-r17 http://thereviewforum.com/monthly_top_10.html/_/monthly-top-10/top-10-free-vpn-service-providers-r17
Edit:
You are right the above does not work. I guess query strings aren't considered. I should have tested it first. Here is an example that I tested to make sure it worked.
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/index.php$
RewriteCond %{QUERY_STRING} ^/page/index.html/_/monthly-top-10/top-10-free-vpn-service-providers-r17$
RewriteRule .? /monthly_top_10.html/_/monthly-top-10/top-10-free-vpn-service-providers-r17 [L,R=301]
I have the following htaccess.
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} !^(www|m)\.DOMAIN\.com$
RewriteCond %{HTTP_HOST} ^([^\.]+).DOMAIN.com$
RewriteRule ^(.*)$ http://DOMAIN.com/index.php?id=%1 [NC,QSA,L,R=301]
The problem is that although it works I need it to still use the subdomain as the URL. So basically now I'm trying to rewrite DOMAIN.com/index.php?id=%1 back into SUDOMAIN.DOMAIN.com so the user sees the subdomain they requested on the address bar and not the http://domain.com/index.php?id=user
I'ver tried all sorts of things but always end up with some sort of infinite loop. Please help!
I already have a wildcard subdomain set up. In conjunction with the htaccess shown above.
The submain doesn't stick, it rewrites itself into the long string shown above. But what im trying to do is get the url ro remain subdomain.domain.com unfortunately the link you posted does peretty much the same as what I have posted above, doesn't really seem to be able to get the sub-domain to stick.
Any ideas?
Not sure if you figured it out yet, but your last line (I believe) should be this:
RewriteRule ^(.*)$ index.php?id=%1 [NC,QSA,L,R=301]
If that does not work try this:
RewriteRule (.*) index.php?id=%1 [NC,QSA,L,R=301]
No expert but I have subdomains working from some other code I found. Hope it helps.
You need to change your DNS settings before. (A record)
There is already an answer for that question.