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!
Related
I have this code in my .htaccess file which does as the comments say:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
Options -Indexes
# redirect all traffic to correct domain
RewriteCond %{HTTP_HOST} ^itl\.|^(www\.)?(integratelecom|integra|integratelecommunications)\b [NC]
RewriteRule ^ https://www.example.net%{REQUEST_URI} [L,R=301,NE]
# redirect admin./ssladmin. sub domain to the correct folder
RewriteCond %{HTTP_HOST} (admin|ssladmin)\.itl\.uk\.net$ [NC]
RewriteRule !^admin/system/ admin/system%{REQUEST_URI} [L,NC]
# redirect subdomain.X to subdomain.example.net
RewriteCond %{HTTP_HOST} ^(?!www\.)([^.]+)\.(?!itl\.)[^.]+\. [NC]
RewriteRule ^ https://%1.example.net%{REQUEST_URI} [L,NE,R=302]
# map subdomains to correct folder
RewriteCond %{HTTP_HOST} ^(?!www\.)([^.]+)\.example\.net$ [NC]
RewriteRule !^subdomains/ subdomains/%1%{REQUEST_URI} [L,NC]
RewriteRule ^(subdomains/|admin/|index\.php$) - [L,NC]
# stop external linking to website but allow listed domains below
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?google.co.uk [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?google.com [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(.*\.)?itl.uk.net [NC]
#RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.|admin\.|ssladmin\.)?example.net [NC]
RewriteRule \.(jpg|jpeg|png|gif)$ – [NC,F,L]
#######################################
############## MAIN SITE ##############
#######################################
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(blog)/(post|tags|category)/([\w-]+)/?$ index.php?id=$1&type=$2&unique=$3 [QSA,NC,L]
RewriteRule ^(blog)/(archives)/([0-9]{4})/([0-9]{2})?$ index.php?id=$1&type=$2&year=$3&month=$4 [QSA,NC,L]
RewriteRule ^(support/knowledgebase)/(article|category|search)/([\w-]+)?$ index.php?id=$1&type=$2&unique=$3 [QSA,NC,L]
RewriteRule ^([a-zA-Z0-9-/_]+)/?$ index.php?id=$1 [L,QSA]
All of the above is working fine, but i need to force every domain and subdomain to use HTTPS, I have tried adding in:
RewriteCond %{HTTPS} off %HTTP_HOST [NC]
RewriteRule ^ https://%1.domain.net%{REQUEST_URI} [L,NE,R=302]
But that keeps returning an Internal Server Error
I also tried these two lines, but that adds %25 to the end of the URL
#RewriteCond %{HTTPS} off
#RewriteRule (.*) https://%{SERVER_NAME}/%$1 [R,L]
To force HTTPs you can use:
RewriteCond %{HTTPS} !=on
RewriteRule ^.*$ https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
It basically says, if HTTPs is not equal to ON, then it will force the website to display using SSL.
Make sure you clear your cache before testing this.
I am new to the whole htaccess language, but I feel like I am close to what I want.
Facts:
parts is a real folder/directory
anotherpart is a real folder/directory
there are no other files in <root> other then index.php
there are no files in the parts folder/directory
Folder/Directory structure:
<root>/index.php
<root>/parts/anotherpart/this.php
What .htacces I have running:
RewriteEngine On
RewriteBase /
RewriteRule ^parts/anotherpart/(.*)$ /$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^www.somewebby.it$ [NC]
RewriteRule ^(.*)$ https://somewebby.it/$1 [R=301,L]
Results:
always having https and no www
hiding parts/anotherpart and showing https://somewebby.it/this.php
The problem:
The requested URL /this.php was not found on this server.
You can replace your current code by this one in your htaccess (which has to be in root folder)
RewriteEngine On
RewriteBase /
# if "www" or http -> redirect to https://domain.com/xxx
RewriteCond %{HTTP_HOST} ^www\. [NC,OR]
RewriteCond %{HTTPS} =off
RewriteRule ^(.*)$ https://somewebby.it/$1 [R=301,L]
# hide "parts/anotherpart/"
RewriteCond %{THE_REQUEST} \s/parts/anotherpart/([^\s]+)\s [NC]
RewriteRule ^ %1 [R=301,L]
# silently rewrite back to "parts/anotherpart/"
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}/parts/anotherpart/$1 -f
RewriteRule ^(.+)$ parts/anotherpart/$1 [L,QSA]
I am a beginner with htaccess stuff and need help checking for mistakes in my htaccess codes below ?
I have 3 set of redirect codes and wondering if they interfere with each other ?
Also wondering if I have redundant redirect code.
Also specifically within the "Stop Hotlinking Code", is this RewriteCond correct?
RewriteCond %{HTTP_REFERER} !^http://(www\.)%{HTTP_HOST}/.*$ [NC]
My goal is to KEEP the www and trailing slash for my URLs , and to remove the index.html for my URLs
Here is my .htaccess File
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
#Force Trailing Slash
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1/ [L,R=301]
#Redirect non-www to www
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1/ [R=301,L]
#Redirect index.html
RewriteCond %{THE_REQUEST} ^.*/index.html [NC]
RewriteRule ^(.*)index.html$ http://www.%{HTTP_HOST}/$1/ [R=301,L]
#Stop Hotlinking
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)%{HTTP_HOST}/.*$ [NC]
RewriteRule \.(gif|jpg|jpeg|bmp|zip|rar|mp3|flv|swf|xml|php|png|css|pdf)$ - [F]
.
Edit:
Questions:
-Is my updated htaccess below correct?
-Do I put RewriteBase / at the top or keep it as is (one with the # Begin WordPress rules and a second RewriteBase / with # Force Trailing Slash ?
-Do I need Options +FollowSymLinks and if yes where do I put this?
Notice that I:
-removed the RewriteEngine On and RewriteBase / from WordPress rules and kept it at the top
-put WordPress Rules BELOW redirects
-removed end slashes for #Redirect non-www to www and #Redirect index.html
RewriteEngine On
# Redirect non-www to www
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
# Redirect index.html
RewriteCond %{THE_REQUEST} ^.*/index.html [NC]
RewriteRule ^(.*)index.html$ http://www.domain.com/$1 [R=301,L]
# Force Trailing Slash
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1/ [L,R=301]
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
# Stop Hotlinking
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)domain.com/.*$ [NC]
RewriteRule \.(gif|jpg|jpeg|bmp|zip|rar|mp3|flv|swf|xml|php|png|css|pdf)$ - [F]
No it's not correct. You can't have % variables or back references in the regex part of the condition. You could use a regex backreference though. Try:
RewriteCond %{HTTP_HOST}:::%{HTTP_REFERER} !^([^:]+):::http://(www\.)\1/.*$ [NC]
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.
Here is my htaccess file
Options +FollowSymLinks
RewriteEngine on
# For Accessing Page http://www.domain.com/news/news-details.php
RewriteCond %{HTTP_HOST} ^www.domain\.com$ [NC]
RewriteRule ^news/news-details.php$ news.php [QSA,NC,L]
# For www.domain.com it should go to the index page
RewriteCond %{HTTP_HOST} ^(www\.)?domain.com$ [NC]
RewriteRule ^(.*)$ index.php [NC,L]
when i type http://www.domain.com/news/news-details.php in the browser it takes me to the index.php page rather than news.php. WHY?
EDIT:
Check these rule
# For www.domain.com it should go to my-index.php page
#
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
RewriteRule ^(.*)$ my-index.php [NC,L]
# For Page URL http://www.domain.com/news/news-details.php
#
RewriteCond %{REQUEST_URI} ^/news/news\-details\.php [NC]
RewriteCond %{HTTP_HOST} ^www\.domain\.com$ [NC]
RewriteRule ^(.*)$ my-news.php [NC,QSA,L]
Options +FollowSymLinks
RewriteEngine On
# For Page URL http://www.domain.com/news/news-details.php
RewriteCond %{HTTP_HOST} ^www\.domain\.com$ [NC]
RewriteRule ^news/news-details\.php$ /my-news.php [NC,QSA,L]
# For Accessing Division Page http://user1.domain.com/news/news-details.php
RewriteCond %{HTTP_HOST} ^(.+)\.domain\.com [NC]
RewriteCond %{HTTP_HOST) !^www\.
RewriteRule ^news/news-details\.php$ /my-news.php?user=%1 [QSA,NC,L]
# For Accessing Users Page
RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(.*)\.domain\.com$
RewriteRule ^$ /users.php?user=%1 [L]
# For www.domain.com it should go to my-index.php page
# (but only if requested resource is not real file)
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /my-index.php [L]
You can't the name of the file in the path.
RewriteRule ^news/news-details.php$ news.php [QSA,NC,L]
here you have the file "news.php" and in the path you have "news".
try another word than news in the path or another name for the file.
for example:
RewriteRule ^news/news-details.php$ news_main.php [QSA,NC,L]