I'm Vietnamese so my english is not good.
I have problem for my cms.
I want to map sub domain to as link via htaccess
Example:
I have links as
?user=example&op=value => example.domain.com/value/ and
domain.com/?user=example1&op=value1 => example1.domain.com/value1/ or
domain.com/?user=example2&op=value2 => example2.domain.com/value2/
..... ....
and many.
I'm using shares hosting so i can't edit file http.config or any one I'm sorry because my English.
Thank all
Try adding the following to the .htaccess file in the root directory of your domain.com site.
RewriteEngine on
RewriteBase /
#if its domain.com
RewriteCond %{HTTP_HOST} ^domain\.com$ [NC]
#capture the user and op query string values
RewriteCond %{QUERY_STRING} (^|&)user=([^&]+)&op=([^&]+)(&|$) [NC]
#and redirect to subdomain with appropriate value
RewriteRule ^ http://%2.%{HTTP_HOST}/%3/? [L,R=301]
Related
I'm working on a site that uses a URL structure like this:
site.com/companyname - general page for company
site.com/companyname/login - login for company admins
The site is switching to a different domain/structure and we need to redirect like this
site.com/companyname > newsite.com/companyname
site.com/companyname/login > newsite.com/login
I'm having trouble getting this to work since the first companyname redirect is happening for both URLs I can target the '/login'.
Thanks!
Got this to work with the following:
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_URI} !login
Rewriterule ^(.*)$ https://newsite.com/$1
RewriteBase /
RewriteCond %{REQUEST_URI} login
Rewriterule ^(.*)$ https://newsite.com/login
We have set up a new website that uses aliases for different country domains, example:
domain.be (main account)
domain.fr (alias)
domain.pl (alias)
The old website (domain.be) contained different languages (e.g. domain.be/pl/). Those Polish page are still indexed in Google on the Belgian domain.
How can we redirect or rewrite domain.be/pl/ to domain.pl?
We can't use a 301 redirect for the subfolder "/pl/" because the domain.pl is an alias and this causes an infinite loop on induplates.pl/pl/.
Thank you in advance for any suggestions.
Check this rules on the top of your .htaccess file. For other langs change domain and lang prefixes in example rules.
<IfModule mod_rewrite.c>
RewriteEngine On
# www.induplates.be/pl/ to www.induplates.pl
RewriteCond %{HTTP_HOST} ^(www\.)?induplates\.be [NC]
RewriteRule ^pl\/$ https://www.induplates.pl/ [R=301,L]
# www.induplates.be/pl/any to www.induplates.pl/any
RewriteCond %{HTTP_HOST} ^(www\.)?induplates\.be [NC]
RewriteRule ^pl\/(.*)$ https://www.induplates.pl/$1 [R=301,L]
</IfModule>
I need to redirect old domain to new with .htaccess
Situation:
www.oldodmain.com/en/categoryA/product1
www.newdomain.com/en/categoryB
Result I am trying to achieve
www.newdomain.com/en/categoryB/categoryA/product1
Tried to do with this code:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?voniospasaulis\.lt$ [NC]
RewriteRule ^.+$ http://www.visaslabas.lt/lt/vonios-iranga/%{REQUEST_URI} [L,R=301]
But I get a result as follow:
www.newdomain.com/en/categoryB/en/categoryA/product1
I need to get rid of /en/before/categoryA to get url like this:
www.newdomain.com/en/categoryB/categoryA/product1
Your rule pattern has to start with en/ and should capture value after en/ in $1 that you can use in target:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(?:www\.)?oldodmain\.com$ [NC]
RewriteRule ^en/(.+)$ http://www.newdomain.com/en/categoryB/$1 [L,NE,NC,R=301]
Also note that I have answered using dummy domain names instead of your actual domain names shown in question.
Make sure to clear your browser cache or use a new browser for testing.
I am building a download site, An users will be able to register and a folder with their username will be created on my server, something like: home/users/username
What I want to accomplish is, if anyone types: username.domain.com in their browser, it will route them to: home/users/username/, and if they type: username.domain.com/file.mp3, it will route them to: home/users/username/file.mp3
If its possible to accomplish sub folders routing, that would be great full aswell, example; home/users/username/sub/file.mp3
Thanks guys
Try adding the following to the .htaccess file in the root directory of your site.
This will rewrite any request to username.domain.com to the correct folder/subfolder and file.
I am assuming that home is a directory in the root folder of your site.
RewriteEngine on
RewriteBase /
#if request for usename.domain.com/anything
RewriteCond %{HTTP_HOST} ^([^.]+)\.domain\.com$ [NC]
#send any request that is not already for home/users to home/users/username/anything
RewriteRule ^(?!home/users/) home/users/%1%{REQUEST_URI} [L,NC]
I tried what Ulrich Palha recommended but no luck. I hope this will help guys like me where Ulrich's answer doesn't work.
# Rewrite username.domain.com/<path> to domain.com/home/username/<path>
#
# Rewrite only if not already rewritten to /home/
RewriteCond $1 !home/
# Skip rewrite if subdomain is www
RewriteCond %{HTTP_HOST} !^www\. [NC]
# Extract (required) subdomain to %1
RewriteCond %{HTTP_HOST} ^([^.]+)\.domain\.com$
# Rewrite to /home/username/URL-path
RewriteRule (.*) /home/%1/$1 [L]
I want to make this url redirect using .htaccess (linux/apache) ..
I want to keep "as is" all calls for www sub domain like this
www.example.com/index.php
www.example.com/test.php?id=1&name=a
www.example.com/whatever.php?whateverurl=xxxx
but I want to redirect all wild card urls like this with the sub domain as extra variable to current unlimited-whatever url variables
for example
xxx.example.com -> example.com/?subdomain=xxx
yyy.example.com/index.php -> example.com/index.php?subdomain=yyy
whatever.example.com/test.php?var=1 -> example.com/test.php?subdomain=whatever&var=1
whatever.example.com/whatever.php?var1=1&var2=2 -> example.com/whatever.php?subdomain=whatever&var1=1&var2=2
is this possible?
Thank you
Once you set up your Wildcard DNS Record you should make your .htaccess file:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.example\.com$
RewriteRule ^(.*)\??(.*)?$ $1?host=%{HTTP_HOST}&%{QUERY_STRING} [L] [L]
This rule works, although it will provide you the whole host, rather than just the subdomain, which you'll have to parse in your PHP.
Thank you for your answer
this rule seems to works
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com$ [NC]
RewriteRule ^/?(.*)$ $1?subdomain=%1 [QSA,L,NE]
for the time without problems ...
thanks again for your answer
Best regards
Vangelis