Rewrite a secondary domain to a subfolder - php

I bought two domains:
www.juridischehulponline.nl
www.onlinejuridischehulp.nl
And I'd like them to link to the subfolder of my hosting: www.zuidveste.eu/juridisch and the new domain has to be displayed as the new domain. So if I surf to www.juridischehulponline.nl I'd like to see: www.juridischehulponline.nl and not www.zuidveste.eu/juridisch.
However, if I rewrite and redirect the subfolder to the new domain, I get a: "too many redirects" error. Since it'll go to www.juridischehulponline.nl where an .htaccess is found which will redirect to www.juridsichehulponline.nl
and if I proxy the domain, my new domain keeps being displayed, however simple blogging systems, such as cutenews, won't work, because they see the absolute path as www.zuidveste.eu/juridisch. But due to the .htaccess, that part will be rewritten and the path of www.juridischehulponline.nl/index.php is given; which doesn't exist.
I've deleted the .htaccess in the /juridisch folder, but I don't know how this can be solved.
Can anyone help me?
Regards,

I wouldn't use proxy, but improve the .htaccess-structure: place only a .htaccess in your zuidveste.eu root:
Options -Indexes
RewriteEngine ON
Options +FollowSymLinks
#redirect non-www to www-domain
RewriteCond %{HTTP_HOST} ^juridischehulponline.nl [NC]
RewriteRule ^(.*)$ http://www.juridischehulponline.nl/$1 [R=301,L]
#redirect non-www to www-domain
RewriteCond %{HTTP_HOST} ^onlinejuridischehulp.nl [NC]
RewriteRule ^(.*)$ http://www.onlinejuridischehulp.nl/$1 [R=301,L]
#redirect non-www to www-domain
RewriteCond %{HTTP_HOST} ^zuidveste.eu [NC]
RewriteRule ^(.*)$ http://www.zuidveste.eu/$1 [R=301,L]
#rewrite other domains to the subfolder, keeping the attributes
RewriteCond %{HTTP_HOST} ^www.juridischehulponline.nl [NC,OR]
RewriteCond %{HTTP_HOST} ^www.onlinejuridischehulp.nl [NC]
RewriteCond %{REQUEST_URI} !^/juridisch/
RewriteRule ^(.*)$ /juridisch/$1 [QSA,L]
This code redirects the 3 non-www domains to their www-alternative, so the visitors will see that they are redirected. On the other hand, if they visit the 2 .nl-domains, the urls will be rewritten and the users will not see this change in their address-bar.
Nevertheless, take care for duplicate content in search engines. I recommend using a canonical-meta-tag, as explained here: http://moz.com/learn/seo/duplicate-content

Related

htaccess routing with url parameters

enter code here Hi I've the following code inside my htaccess file.
My wildcard subdomain routes to "mainfolder" - here i placed the htaccess file.
I've the following folders
"mainfolder"
"mainfolder/sub1"
"mainfolder/sub2"
etc.
Calling the subdomain - sub1.domain.com it should route to the subfolder "sub1" (subfolder=subdomain).
I tried to do it with this code
#Redirect to subdomainfolder if no special page is called
RewriteCond %{HTTP_HOST} ^(.*)\.domain\.com$ [NC]
RewriteRule ^$ %1/index.html [L]
#Redirec to subdomainfolder if a special page is called
RewriteCond %{HTTP_HOST} ^(.*)\.domain.com(.*)$ [NC]
RewriteRule ^(.*) %1/$1 [L]
The first rule works well, but if I add the second rule I receive a internal server error.
Whats wrong with this - how how I can change the first rule in this way, that it works with all url-parameters after .com - that was the reasons for me to add the second rule.
Hope I get help for this. thanks a lot.
A lot of web hosts today provide an easy implemention for subdomain creation in their administration panels. You just need to to go there, choose you subdomain name, and then point it to a directory in your tree.
If you can't, then it will be a little more complicated (You will need to resolve that subdomain to your server ip, configure some virtual hosts ... etc) and you may not have enough privileges to do that (unless you are on a dedicated server).
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com$1 [L,R=301]
RedirectMatch 301 ^/subfolder/(.*)$ http://subdomain.example.com/$1
LIke
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$
RewriteRule ^sub1/(.*)$ http://sub1.example.com/$1 [L,QSA,R=301]
RewriteCond %{HTTP_HOST} ^sub1\.example\.com$
RewriteCond %{REQUEST_URI} !^sub1/
RewriteRule ^(.*)$ /sub1/$1 [L,QSA]
If more understanding step wise then follow https://beginnersbook.com/2013/08/redirecting-from-subdirectory-to-subdomain-using-htaccess/

how to redirect domain name with directory

I have one project online and it on two diffrent domains 1)www.example.com and 2)www.example.co.in. now, I want to redirect
www.example.co.in/category/
to
www.example.com/ceramic+industry/
And I want to redirect it through .htaccess or from server. I tried from server that only redirect domain name not directory, and also tried from .htaccess where I can redirect only domain or only directory not when both domain and directory combine. My project in php. So, you can give advise if it's possible in php also.
Add following rule in .htaccess(placed at root of website www.example.co.in):
Options +FollowSymlinks
RewriteEngine On
RewriteRule ^category/(.*)$ http://www.example.com/ceramic+industry/$1 [L,R=301]
or use 302 for temporary redirects.
IF you also want to redirect whole .co.in website to .com THEN add next line(remember in .com website's .htaccess these two Rules should not be there.)
RewriteRule ^category/(.*)$ http://www.example.com/ceramic+industry/$1 [L,R=301]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
If for any reason you are bound to use same .htaccess on both site then use condition like this:
RewriteCond %{HTTP_HOST} !^www.example.com$ [NC]
RewriteRule ^category/(.*)$ http://www.example.com/ceramic+industry/$1 [L,R=301]
RewriteCond %{HTTP_HOST} !^www.example.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
============================================================
Solution to your another query:
This can be done by PHP. As I guessed all URL after category/ is handled by one PHP page.
in that PHP page code this at top:
if(isset($_GET['company'])){
$company=$_GET['company'];
$companyNew=str_replace('_','+',$company);
if($company!=$companyNew){
header("location:/category/?company="+$companyNew,true,301);
//header("location:/ceramic+industry/?company="+$companyNew,true,301);
exit;
}
}
You can try this:
RewriteCond %{HTTP_HOST} ^your.first.domain$
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.*)$ http://your.second.domain/$1 [R,L]
This will redirect, if your request contains existing directory name.
Answer to your comment. You can try this:
RewriteCond %{ENV:REDIRECT_FINISH} !^$
RewriteRule ^ - [L]
RewriteCond %{QUERY_STRING} ^company=(.*)\_(.*)$
RewriteRule ^(.*)$ /$1?company=%1+%2 [R,L,E=FINISH:1]
First two lines allow you to prevent infinite loop redirect.

Redirect all non-www to www except one subdirectory using htaccess.

If want to redirect all non-www requests to my site to the www version. All I need to do is add the following code to my .htaccess file.
RewriteCond %{HTTP_HOST} ^mydomain\.com [NC]
RewriteCond %{REQUEST_URI} !^/subfolder
RewriteRule .* http://www.mydomain.com%{REQUEST_URI} [R=301,L]
The problem is that when I write for example mydomain.com/products-1 (hidden URL for mydomain.com/products?category=1), all parameters become visible, even though they are specified on the .htaccess file, and I get an output url (after the redirect) of www.mydomain.com/products-1?category=1
How can I fix this? Is there any kind of problems with the .htaccess code above?
Try Changing your RewriteRule:
RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
RewriteCond %{REQUEST_URI} !^/subfolder
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
I prefer this because it will catch all *.domain.com. If that is not what you want, then use your original HTTP_HOST rule.
If my logic is working this morning, this rule should rewrite any requests that do not match:
www.example.com
and do not contain
/subfolder
to
www.domain.com/URI

htaccess domain redirect to newdomain

I have the domain www.oldsite.com and i set a redirect to forward to www.newsite.com/new
but when i google search old site all of its sub links go to www.newsite.com/new/sublink
How do i edit the htaccess file so that the sub links never pass though
RewriteCond %{HTTP_HOST} ^oldsite\.com*$ [OR]
RewriteCond %{HTTP_HOST} ^www\.oldsite\.com*$
RewriteRule ^/?$ "http\:\/\/www\.newsite\.com\/new" [R=301,L]
In short all links involved in oldsite.com should redirect to newsite.com/new
I read the below but it didnt seem to help to much.
htaccess: domain hosted on subdirectory
The below .htaccess should be place on the root folder of the old domain only:
RewriteCond %{HTTP_HOST} ^(www\.)?oldsite\.com$ [NC]
RewriteRule ^ http://www.newsite.com/new [R=301,L]
It will redirect anything from the old domain to the new one, for example:
http://oldsite.com/someurl
Will go to:
http://www.newsite.com/new
No URLs from the old site will be passed down to the new site, they will all be sent to /new.
NOTE: make sure you do not have any additional .htaccess files in other folders of the old domain as those will set null the previous rules.
If you want to send only the main domain to the new one without any URLs within:
RewriteCond %{HTTP_HOST} ^(www\.)?oldsite\.com$ [NC]
RewriteRule ^/?$ http://www.newsite.com/new [R=301,L]
A different way would be to handle all the URLs on the new site, which would be like the below .htaccess:
RewriteCond %{HTTP_HOST} ^(www\.)?oldsite\.com$ [NC]
RewriteRule ^ http://www.newsite.com/new%{REQUEST_URI} [R=301,L]
It will redirect anything from the old domain to the new one, for example:
http://oldsite.com/someurl
Will go to:
http://www.newsite.com/new/someurl
If you do not wish the new to show up simple remove /new from the rule above.

I want to redirect old url to new rewrite url using htaccess or php

I have a problem since i using rewrite url..
MY OLD URL:
Website.com/index.php?act=appdetail&appid=oWV
New Rewrite URL
http://website.com/angry_birds_rio-appdetail-oWVi.html
But all my old url are indexed in google and if any one come to my website its display the old URL and google also INDEXED the NEW URL. its make duplicate page on website problem.
Let me know the solution
My rewrite URL htaccess
RewriteEngine On
RewriteRule ^([^-])-([^-])-([^-])-([^-])-([^-]*).html$ index.php?appanme=$1&act=$2&appid=$3&page=$4&cat=$5 [L]
RewriteRule ^([^-])-([^-])-([^-])-([^-])-([^-])-([^-]).html$ index.php?appanme=$1&act=$2&appid=$3&page=$4&cat=$5&sString=$5 [L]
RewriteRule ^([^-])-([^-])-([^-]*).html$ index.php?appanme=$1&act=$2&appid=$3[L]
Here is your .htaccess file:
RewriteEngine on
RewriteRule ^/index.php?act=appdetail&appid=oWV$ http://website.com/angry_birds_rio-appdetail-oWVi.html [R=301,L]
You'll need to inform to web crawlers about the redirection, you cando it with a 301 code.
Appears the rule are .htaccess based; you need an additional set of rules to permanently redirect (301) BROWSER/CRAWLER requests for the index.php pages, if a set of CGI arguments are present, to the appropriate alias, this will tidy up Google in a few weeks. Then your rules above e.g.
RewriteEngine On
RewriteBase /
#Permanently redirect BROWSER requests for the index.php?xxx to the appropriate page alias:
RewriteCond %{THE_REQUEST} /index.php [NC]
RewriteCond %{QUERY_STRING} ^appanme=([^&]+)&act=([^&]+)&appid=([^&]+)&page=([^&]+)&cat=([^&]+)&sString=([^&]+) [NC]
RewriteRule ^.* http://%{HTTP_HOST}/%1-%2-%3-%4-%5-%6.html [R=301,L]
RewriteCond %{THE_REQUEST} /index.php [NC]
RewriteCond %{QUERY_STRING} ^appanme=([^&]+)&act=([^&]+)&appid=([^&]+)&page=([^&]+)&cat=([^&]+) [NC]
RewriteRule ^.* http://%{HTTP_HOST}/%1-%2-%3-%4-%5.html [R=301,L]
RewriteCond %{THE_REQUEST} /index.php [NC]
RewriteCond %{QUERY_STRING} ^appanme=([^&]+)&act=([^&]+)&appid=([^&]+) [NC]
RewriteRule ^.* http://%{HTTP_HOST}/%1-%2-%3.html [R=301,L]
# Followed by: YOUR RULES FROM ABOVE
Note:
1) There appears to be a typo in YOUR second rule: sString=$6 NOT sString=$5
2) The Apache mod_rewrite documentation is worth a read if your unclear as to what the above rules do, or if you want something a little more abstract consider the following post.

Categories