I have a multilanguage website in joomla. The FaLang component creates the following URLs:
www.myDutchDomain.nl/nl/
www.myDutchDomain.nl/en/
www.myDutchDomain.nl/de/
I have 2 other URLs which should redirect to English and German URL:
www.myEnglishDomain.eu >> www.myDutchDomain.nl/en/
www.myGermanDomain.de >> www.myDutchDomain.nl/de/
After redirect I want to see myEnglishDomain and myGermandomain in URL. If I'm not mistaken it's called server alias.
How can I create a server alias for this purpose?
You should be able to use mod rewrite to solve this by adding lines to your .htaccess file, allowing anything on your country domains 'www.myEnglishDomain.eu/{wildcard}' to be rewritten to the country path '/en/{wildcard}'.
First you must make sure that the bindings for each domain are pointing to this website.
Then add the following lines to your .htaccess file:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.myEnglishDomain.eu$[NC]
RewriteRule ^(.*)$ /en/$1 [L]
RewriteCond %{HTTP_HOST} ^www.myGermanDomain.de$ [NC]
RewriteRule ^(.*)$ /de/$1 [L]
If you need the domain within the browser to update to myDutchDomain.nl, then doing the following instead:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.myEnglishDomain.eu$ [NC]
RewriteRule ^(.*)$ http://www.myDutchDomain.nl/en/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^www.myGermanDomain.de$ [NC]
RewriteRule ^(.*)$ http://www.myDutchDomain.nl/de/$1 [R=301,L]
For further help, here is a mod rewrite cheat sheet: http://www.cheatography.com/davechild/cheat-sheets/mod-rewrite/
Disclaimer: I have not been able to test the above rules, please let me know if this contains syntax or other errors so to maintain an accurate reference for other people.
Related
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/
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.
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
This question has probably been asked for over a thousand times, but I've tried so many scripts, and googled so long while finding nothing, I thought, let's just ask.
I simply want m.daltonempire.nl to be redirected to daltonempire.nl/m/ without the user seeing the URL change.
So if m.daltonempire.nl/hello.php is requested, I want the user to keep seeing this URL, while the page given is actually daltonempire.nl/m/hello.php.
Note: I do not want www., so simply http://m.daltonempire.nl
Thanks in advance,
Isaiah v. Hunen
Add this to your .htaccess in your web root / directory
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^m\.daltonempire\.nl$ [NC]
RewriteCond %{REQUEST_URI} !^/m(/|$) [NC]
RewriteCond %{REQUEST_FILENAME} !-d # not a dir
RewriteCond %{REQUEST_FILENAME} !-f # not a file
RewriteRule ^(.*)$ m/$1 [L]
The %{REQUEST_FILENAME} conditions would let you access /exists.php and not rewrite it to /m/exists.php. Remove those two if you want to rewrite even if that may potentially override existing files and directories.
Try this example:
RewriteCond %{HTTP_HOST} ^([^/.]+)\.example\.com$
RewriteCond %1 !^(www|ftp|mail)$ [NC]
RewriteRule (.+)$ "http://example.com/%1" [L,P]
Any requests http://test.example.com will be mapped to http://example.com/test/...
Try googling dynamic subdomain with php and htaccess to get better search results.
I have set CNAME of my sub domain below:
blog.mydomain.com
to my wordpress that installed in folder /blog/ under root directory.
Formerly I need to use this url to call wordpress:
http://blog.mydomain.com/blog/
which is ugly. I have tried many code to redirect:
http://blog.mydomain.com/
to the folder so I can use it as my wordpress url.
Finally I got .htaccess setting that is work:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^blog\.mydomain\.com$
RewriteCond %{REQUEST_URI} !^/blog/
RewriteRule (.*) /blog/$1
I have also CNAME other subdomain: http://forum.mydomain.com to mybb installation in folder /forum/mybb/ so the .htaccess need to put [L] on each of RewriteRule code as below.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^forum\.tophyips\.info$
RewriteCond %{REQUEST_URI} !^/forum/mybb/
RewriteRule (.*) /forum/mybb/$1 [L]
RewriteCond %{HTTP_HOST} ^blog\.tophyips\.info$
RewriteCond %{REQUEST_URI} !^/blog/
RewriteRule (.*) /blog/$1 [L]
In case you want to use the code please don't forget to set the site url and cookie path in the application config file follow to the setting to make the redirection work properly.
I am working on the htaccess file for my mvc site. The software that the company purchased for the site works only without the www, so I was able to fix up the htaccess to allow www in the URL since most of our affiliates are going to try to use it anyway. However, this renders the siteurl.org/index.php/admin and the siteurl.org/index.php/members unreachable. I'm trying to exclude these URL's from the www forward to non-www but everything I know and can find seems to relate to non-MVC sites, and it seems that mvc sites are set up differently across the board so the examples I'm finding aren't working for me.
Here's my current htaccess (I had to comment out the forwarding lines to allow admins to access the admin section and affiliates to access the member section)
<Files ~ "serial.txt$">
Order allow,deny
Deny from all
</Files>
RewriteEngine On
#RewriteCond %{HTTP_HOST} !^www\. [NC]
#RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteRule ^aff/(.*)$ /index.php/aff/?aff=$1 [R,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [R=301,NC]
If it could be addressed at the same time, I'd also love a pointer on how to clean up that URL so that we could type in siteurl.org/admin as opposed to siteurl.org/index.php/admin (same for members), and also to show the affiliate name in the URL (it's currently cleaning up the URL to remove the /aff/affiliateusername but affiliates would like to see their name in the URL). If anybody has a great link to specific resources on writing htaccess for MVC I would be eternally grateful. Thank you in advance for any assistance.
Let's be clear on three things before going into explanations:
Apache doesn't have a care in the world whether your site is built on the MVC approach/design pattern or not. It. Doesn't. Even. See. It. To it, it sees htaccess mod_rewrite rules.
Whoever puts a serial code in serial.txt on the root is just begging for it to get nicked using a file include vulnerability in PHP.
This is suspiciously similar to CodeIgniter in rewrite rules.
Now. Your rules:
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
This rule will match only if the http host does not start with www. . If this is true, then it'll redirect to the http ://www. version.
Based on your description, you want the opposite: Your CMS does not work with www.. So, you will want this:
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule ^(.*)$ http://mydomain/$1 [R=302, L]
Note that you'll need to hardcode your domain in there. Sucks.
Next set of rules:
RewriteRule ^aff/(.*)$ /index.php/aff/?aff=$1 [R,L]
This is bog-standard - redirects aff/whatever to /index.php/aff/?aff=$1
For the future, change it to this:
RewriteRule ^aff/(.*)$ /index.php?/aff/?aff=$1 [L]
This will clean up the URL and prevent an Apache rewrite cycle.
Next one:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [R=301,NC]
These will wildcard-match anything that does not exist. Same thing as before, change the last line to this:
RewriteRule ^(.*)$ /index.php?$1 [L]
This will, again, make the rewrite transparent.
P.S: get a real CMS developer. 301s are hardly useful.