I am trying to create a website that would create its portfolio, currently once created your page that has the URL domain.com/content/username but I would like to create a subdomain for each user therefore username.domain.com. Do you have any idea how to do this? I tried this:
Options +FollowSymLinks -Multiviews
RewriteEngine on
RewriteBase /
#
# Canonicalize the hostname
RewriteCond www.%{HTTP_HOST} ^(www)\.(mine-app\.fr) [OR]
RewriteCond %{HTTP_HOST} ^www\.([^.]+)\.(mine-app\.fr) [OR]
RewriteCond %{HTTP_HOST} ^([^.]+)\.www\.(mine-app\.fr) [OR]
RewriteCond %{HTTP_HOST} ^([^.]+)\.(mine-app\.fr). [OR]
RewriteCond %{HTTP_HOST} ^([^.]+)\.(mine-app\.fr):[0-9]+
RewriteRule (.*) http://%1.%2/$1 [R=301,L]
#
# If subdomain is NOT www
RewriteCond %{HTTP_HOST} !^www\.mine-app\.fr [NC]
# Extract (required) subdomain to %1
RewriteCond %{HTTP_HOST} ^([^.]+)\.mine-app\.fr$
# Rewrite if requested URL resolves to existing file or subdirectory in /content/<content>/ path
RewriteCond %{DOCUMENT_ROOT}/content/%1/$1 -f [OR]
RewriteCond %{DOCUMENT_ROOT}/content/%1/$1 -d
RewriteRule (.*) /content/%1/$1 [L]
But nothing worked. How can I solve this?
Related
I am using opencart e-commerce package and have my main domain redirect to use https & www but i require some sub domains, so far in my .htaccess i have
RewriteBase /
RewriteCond %{HTTP_HOST} ^mydomain.co.uk
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^(.*)\.mydomain\.co.uk$
RewriteCond %1 !^(www|ftp|mail)$ [NC]
RewriteCond %{REQUEST_URI} !^/subdomains/(.*)
RewriteRule ^(.*)$ /subdomains/%1/$1 [L]
This works fine and i can create new sub domains in the folder called subdomains - but if a folder is not found it shows a 500 error i have tried adding in checks for folders and files but this still returning 500 errors with the error -
Request has exceeded the limit of 10 internal redirects
RewriteCond %{HTTP_HOST} ^(.*)\.mydomain\.co.uk$
RewriteCond %1 !^(www|ftp|mail)$ [NC]
RewriteCond %{REQUEST_URI} !^/subdomains/(.*)
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.*)$ /subdomains/%1/$1 [L]
What can i use that will only show the subdomain if the folder and file is there otherwise redirect the request back to the main domain?
So I have managed to stop the 500 errors and show a 301 moved permanently page rather then a redirect - for some reason I cannot figure out how to redirect back to the main domain if the directory doesn't exist
## redirect the main domain to www-https
RewriteBase /
RewriteCond %{HTTP_HOST} ^mydomain.co.uk
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]
## check the subdomain folder
RewriteCond %{HTTP_HOST} ^(.*)\.mydomain\.co.uk$
RewriteCond %1 !^(www|ftp|mail)$ [NC]
RewriteCond %{REQUEST_URI} !^/subdomains/(.*)
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -s
RewriteRule ^(.*)$ /subdomains/%1/$1 [L]
## show the index.php file in the subdomain directory
## doesn't work but shows a 301 page ?
RewriteCond %{HTTP_HOST} ^(.*)\.mydomain\.co.uk$
RewriteCond %{REQUEST_FILENAME} !-f [OR]
RewriteCond %{REQUEST_FILENAME} !-s
RewriteRule ^(.*) /subdomains/index.php [R=301]
im trying to redirect my subfolder to other domain and i want that work without changing the url
the code about htaccess inside /folder is:
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/
RewriteRule ^(.*) http://domain2.com/$1 [P]
this redirect to the second domain but the url changed..
could it be a conflict with the htacces in the root?
root htaccess:
RewriteEngine on
# Remove ".php" from urls
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
# Redirect to https version
RewriteCond %{HTTP:X-Forwarded-Proto} =http [OR]
RewriteCond %{HTTP:X-Forwarded-Proto} =""
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
#indexies
Options -Indexes
DirectoryIndex home.php
im new with htaccess but it all seems correct..
I am rewriting my urls with this htaccess:
RewriteEngine on
# Options +FollowSymlinks
RewriteBase /
# REDIRECT MAIN DOMAIN
RewriteCond %{HTTP_HOST} ^(www.)?domain.nl$
# /subfolder/
RewriteCond %{REQUEST_URI} !^/www.domain.nl/
# Don't change this line.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# /subfolder/
RewriteRule ^(.*)$ /www.domain.nl/$1
# site
# subfolder/
RewriteCond %{HTTP_HOST} ^(www.)?domain.nl$
RewriteRule ^(/)?$ www.domain.nl/ [L]
# SUBDOMAINS to /sub.domain.nl/
RewriteCond %{HTTP_HOST} ^([^.]+)\.domain\.nl$ [NC]
RewriteCond %{HTTP_HOST} !^www\.domain\.nl$ [NC]
RewriteRule ^(.*)$ http://domain.nl/%1.domain.nl/$1 [P,L]
This will take subdomains to there subfolder. So x.domain.nl goes to domain.nl/x.domain.nl.
However, this also shows as [SCRIPT_URI] => http://domain.nl/x.domain.nl/
Is it possible that all the $_SERVER variables show just x.domain.nl on all the variables and not the long version?
Thanks!
First I directed my /example folder to main domain. Now, I'd like to redirect some of the pages to HTTPS. Pls, anyone could advice me about the code:
# com upload yonlendirme
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?domain.com$
RewriteCond %{REQUEST_URI} !^/example/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /example/$1
RewriteCond %{HTTP_HOST} ^(www.)?domain.com$
RewriteRule ^(/)?$ example/index.php [L]
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
#redirect www.mydomain.com to mydomain.com (or any other subdomain)
RewriteCond %{HTTP_HOST} !^domain.com$ [NC]
RewriteRule ^(.*)$ http://domain.com/$1 [L,R=301]
#force https for certain pages
RewriteCond %{HTTPS} !=on
RewriteRule ^(index\.php?route=account/register|index\.php?route=account/login|index\.php?route=account/account|index\.php?route=checkout/checkout)$ https://%{HTTP_HOST}%{REQUEST_URI}[L,R]
You can't match against the query string (everything after the ?) in a rewrite rule. You'll need to match against the %{QUERY_STRING} variable in a rewrite condition:
RewriteCond %{HTTPS} off
RewriteCond %{QUERY_STRING} ^route=(account/register|account/login|account/account|checkout/checkout)
RewriteRule ^index.php$ https://%{HTTP_HOST}%{REQUEST_URI}[L,R]
You may also want to move that rule up to the top of your htaccess file so the routing to the example folder doesn't interfere with the redirects.
I'm looking for a htaccess code to redirect my url's like this :
http://01.mydomain.com/subdir/xyz [OR]
http://www.01.mydomain.com/subdir/xyz [OR]
http://02.mydomain.com/subdir/xyz [OR]
http://www.02.mydomain.com/subdir/xyz
TO : http://www .mydomain.com/xyz
and in this case xyz is dynamic and could be any value. and subdir is constant
Assuming subdir is constant, the following is one way:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^01.mydomain.com [OR]
RewriteCond %{HTTP_HOST} ^www.01.mydomain.com [OR]
RewriteCond %{HTTP_HOST} ^02.mydomain.com [OR]
RewriteCond %{HTTP_HOST} ^www.02.mydomain.com
RewriteRule ^subdir/(.*)$ http://www.mydomain.com/$1 [L,R=301]
RewriteRule ^/subdir/(.*)/?$ /$1 [R=301,L]