I run TYPO3 with a normal site and a subdomain in the same TYPO3 installation. On the normal site, automatically a mobile device is detected and then rerouted to the subdomain.
In my subdomain the visitor is redirected to the correct page in the TYPO3 tree, using following .htaccess file.
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{http_host} ^m.mysite.com [NC]
RewriteRule ^(.*)$ http://m.mysite.com/index.php?id=74 [L]
What happens is that the visitor ends up in an endless loop where he is sent to the TYPO3 site and then to the subdomain and back again.
To get this working, I also need to change the working directory to www.mysite.com (I also have another provider where I can make these changes using a cpanel, and that site runs perfectly). I have been looking everywhere and have tried almost anything, but I simply do not have enough knowledge to change the working directory.
So what code should I use to change the working directory?
Use RewriteCond to not follow this rule for index.php.
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{http_host} ^m.mysite.com [NC]
# Failing the index.php check, the usual test is to look for any
# existing file
# EDIT: Changed URI to start with / - should work per comments
RewriteCond %{REQUEST_URI} !^/index.php
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ http://m.mysite.com/index.php?id=74 [L]
Related
I have the following code in my .htaccess file:
RewriteEngine on
RewriteCond %{HTTP_HOST} mysitedomain\.com [NC]
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^(.*)$ /web/$1 [L]
I'm currently using CPanel and CPanel does not allow you to set a new Document Root. So have my drupal files in my CPanel "public_html" directory with the composer.json files etc..and web directory that has all the Drupal related files. I am trying to get the site vistors to rewrite or redirect to www.mysitedomain.com/web for subsequent pages.. I tried the code below but does not seem to work.. Am i missing something?
To be specific.... I need the site to 1. load www.mysitedomain.com/web when www.mysitedomain.com is requested. 2. And ensure /web is is front of every subsequent request page request within the site (ie. www.mysitedomain.com/web/products should load instead of www.mysitedomain.com/products)
I am not sure what your question is, but I think you need something like this:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
What it does: If the URL does not resolve to a file or directory in the present directory, put index.php in front of it.
I'd assume your index.php would then include the Drupal framework.
After redirecting my client domain to my server i created rewrite rule in root folder .htaccess file to point domain to a subfolder1 (joomla website):
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?myclientdomain\.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !/subfolder/
RewriteRule ^(.*)$ /subfolder1/$1 [L]
Everything worked fine but today i found out that i can access any other subfolder in my server by entering for example: myclientdomain.com/subfolder2 and what's worse google can index that and show it in search results.
If there is any way to redirect a domain in a way that I won't be able to access any other folder on my server?
I would really appreciate help as I searched throughout google for answer, my server tech support said that they don't really support these kind of problems (they only gave me a piece of code from above) and I don't really know anything about .htaccess rules and how it works.
Try this
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?myclientdomain\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/subfolder\/?(.*)?$
RewriteRule ^(.*)$ /subfolder1/$1 [L]
Change above rule to:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?myclientdomain\.com$ [NC]
# if current URI is not starting with /subfolder/ then route to /subfolder/
RewriteRule ^((?!subfolder1/).*)$ subfolder1/$1 [L,NC]
i have a problem.
situation:
- old site in main directory with first .htaccess (www.domain.com)
- new site (joomla) in subdirectory /new with second .htaccess (www.domain.com/new)
what i need:
- on www.domain.com must be new site
- old site must be accessible via a direct link
- new site link must be www.domain.com, not www.domain.com/new
I tested probably every guide that I found but nothing works. the only thing I managed is redirected to a new page.
in first htaccess:
RewriteEngine On
RewriteRule ^$ /new [L]
RewriteCond %{HTTP_HOST} ^www.(.*) [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,NC,L]
second htaccess:
all off
please help me.
thx
This should be as simple as rewriting every url that does not already point to a resource to that resource with the new prefix, unless it already has that prefix.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/new/
RewriteRule ^(.*)$ /new/$1 [L]
Please note that you have to clear your cache since you used permanent redirects to test. Never test with permanent redirects. Instead use temporary redirects until you have verified everything works as expected.
I've been trying to solve a problem for the past few hours. I am desperate for help!
I have two domains:
rd1.example.com/drupal
rd2.example.com
I have a drupal installation in rd1.example.com/drupal/
Further, I started creating content on drupal in a url alias: rd1.example.com/drupal/rd2/
What I want to do is used the second website to point to that specific content within my drupal installation:
rd2.example.com -> rd1.example.com/drupal/rd2/
I don't want it to be a redirect but an internal hidden redirect. The user will think that they are on rd2.example.com.
I've switched rd2.example.com to point to the directory where drupal is installed. I've been trying to edit the rewriterules on drupal's .htaccess but with no luck. Any help is greatly appreciated. Here is my rules so far:
#Existing settings
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_HOST} !^rd2\.example\.com [NC]
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^ index.php [L]
#New rules to accomodate for rd2.example.com
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_HOST} ^rd2\.example\.com$ [NC]
RewriteCond %{DOCUMENT_ROOT}/rd2%{REQUEST_URI} -f
RewriteRule .* /rd2/$0 [L]
Drupal relies on the server variables to process its request. That means when you internally rewrite to /rd2/$0, drupal doesn't know what to do with that. You'll need to reverse proxy *from the rd2` subdomain instead. So leave drupal the way it is, then on the rd2.example.com document root, add:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^rd2 [NC]
RewriteRule ^(.*)$ http://rd1.example.com/drupal/rd2/$1 [L,P]
This will only work if you have mod_proxy loaded on your server, otherwise nothing will happen. Mod_proxy can only be turned on through your server's config. You could also setup the reverse proxy from the vhost config for the rd2 subdomain:
ProxyPass / http://rd1.example.com/drupal/rd2/
Beside of proxy, you may also consider to use a symbolic link that made by a shell command like so:
ln -s /path/to/rd1 /path/to/drupal/rd2
More details is explained in Multi-site - Sharing the same code base
I have been having a very difficult time editing my .htaccess file to do these three things together. I have been able to get each part separately but I just do not understand how the logic flow works to get them all to work.
This is the best I have been able to pull together using the demo at bluehost support
http://helpdesk.bluehost.com/index.php/kb/article/000347
I appreciate any help resolving this issue.
# Use PHP5 Single php.ini as default
AddHandler application/x-httpd-php5s .php
# Bluehost.com
# .htaccess main domain to subdirectory redirect
# Copy and paste the following code into the .htaccess file
# in the public_html folder of your hosting account
# make the changes to the file according to the instructions.
# Do not change this line.
RewriteEngine on
# Change yourdomain.com to be your main domain.
RewriteCond %{HTTP_HOST} ^(www.)?sampleurl.com$
# Change 'subdirectory' to be the directory you will use for your main domain.
RewriteCond %{REQUEST_URI} !^/folder/
# Don't change this line.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Change 'subdirectory' to be the directory you will use for your main domain.
RewriteRule ^(.*)$ /folder/$1
# Change yourdomain.com to be your main domain again.
# Change 'subdirectory' to be the directory you will use for your main domain
# followed by / then the main file for your folder, index.php, index.html, etc.
RewriteCond %{HTTP_HOST} ^(www.)?sampleurl.com$
RewriteRule ^(/)?$ folder/index.php
RewriteCond %{HTTP_HOST} ^sampleurl\.com$ [OR]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{SERVER_PORT} 80
RewriteRule (.*) https://www.sampleurl.com/$1 [L]
# For security reasons, Option all cannot be overridden.
# Options All -Indexes
# Options ExecCGI Includes IncludesNOEXEC SymLinksIfOwnerMatch -Indexes
Update:
Well after a long time using the following I have run into issues.
IndexIgnore *
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} !^/site/
RewriteRule (.*) https://www.example.com/site/$1 [L,R]
RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} ^/site/
RewriteRule (.*) https://www.example.com/$1 [L,R]
RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
RewriteCond %{SERVER_PORT} 443
RewriteCond %{REQUEST_URI} !^/site/
RewriteRule (.*) https://www.example.com/site/$1 [L,R]
New Issues.
Bluehost has an application that quickly installs and updates open source applications like wordpress, joomla, phpbb etc. Well apparently my new super .htaccess file completely breaks their system. The only way I can run updates and installs is to move the .htaccess to .htaccess.bak until the upgrade or install is complete. Then move it back.
I can't create any .htaccess on other sites that I host in other directories. e.g. I have a master account that I store in /www/site/ that this script forces requests into. Unfortunately my other sites stored in /www/site2/ and /www/site3/ don't work well. First I have to create a blank .htaccess to prevent it from pulling the .htaccess above found in /www/. For some reason if I try to do anything like force www.site2.com I get 500 error's saying I am forcing too many redirects.
I have a theory that my solution above needs to be a little more specific, to make sure it only effects request sent to example.com. (I think the line with anything not containing /site/ is a little to broad).
I appreciate any support resolving this. Would save me a bit of headaches!
Update II:
I do not believe I have access to apache config. Only option I see in cpanel is apache handlers (not really sure what that section does).
I will submit a ticket to see what location the simplescripts server runs from. I believe it runs from "https://www.simplescripts.com". What edit would you recommend I add to ignore this domain?
My host bluehost starts you with a primary account and then subdomains. The primary account's location is set at user\www. Unfortunatly this gets messy when you try to host multiple domains. That is why I use .htaccess to force requests that hit that directory into the \site\ directory. Thus trapping the primary site into the \site\ directory.
I think the relocation issue I was having with one of my subdomains was due to wordpress trying to force a domain without www and then me writing an .htaccess file forcing www. That caused the infinite loop, not my .htaccess file this thread is about. If I can resolve the simplescripts issue I am gmoney ;)
I'd think something like this would work
RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} !^/folder/
RewriteRule (.*) https://www.example.com/folder/$1 [L,R]
RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} ^/folder/
RewriteRule (.*) https://www.example.com/$1 [L,R]
but I confess I haven't tested. You can add in all the don't redirect if the file exists, etc., if you want.
In case you haven't seen it, here is the mod_rewrite documentation.
edit:
In response to updated question:
The first thing I notice is that it appears you may have enough control over your setup to put the rewrites in the Apache config files (in the VirtualHost sections) instead of in htaccess files, that'll immediately solve your problem with your other sites.
The first problem, it sounds like you'll need to add RewriteCond to exclude whichever URLs the Bluehost software uses. Either that, or access the Bluehost software under a different VirtualHost (once you've put the rewrite stuff inside the VirtualHost blocks).
If you can't edit your Apache config, then the easiest fix for the other sites it to not make them a subdirectory (on the filesystem) of your main site. That's rather weird, anyway. Move your main site to a sub-directory of /www as well if need be.
Personally, I put all sites in /srv/www/com.site-name.www on my servers (that is, reverse order, with the top-level-domain first, it makes related stuff group together when sorted alphabetically. E.g., when you have www.example.com and static.example.com)
This seems to do everything I needed. Probably a shorter way to get this done but it works!
IndexIgnore *
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} !^/folder/
RewriteRule (.*) https://www.example.com/folder/$1 [L,R]
RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} ^/folder/
RewriteRule (.*) https://www.example.com/$1 [L,R]
RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
RewriteCond %{SERVER_PORT} 443
RewriteCond %{REQUEST_URI} !^/folder/
RewriteRule (.*) https://www.example.com/folder/$1 [L,R]