I have a project with a special hosting structure:
www
domains
projectName (example.com)
I have to set the baseUrl config.baseURL = http://example.com/domains/example.com/.
Url example http://example.com/domains/example.com/index.php?id=4.
If I use only config.baseURL = http://example.com/. The site works but sessions do not work and user cannot log (he can log in but after reload he is logged out)
I need to have url only with http://example.com/index.php?id=x.
There is 1 htaccess in the www folder with these rules.
RewriteEngine On
RewriteCond %{REQUEST_URI} !^domains/
RewriteCond %{REQUEST_URI} !^/domains/
RewriteCond %{HTTP_HOST} ^(www\.)?(.*)$
RewriteCond %{DOCUMENT_ROOT}/domains/%2 -d
RewriteRule (.*) domains/%2/$1 [DPI]
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,QSA,L]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^domains/[^/]+/(.+[^/])$ /$1/ [R]
And another is in my project folder.
I am sure there will be just an easy htaccess rule. But I do not have any experience with it. I tried to use the solution from Mod Rewrite Hide Folder but it did not help. I tried to use it in both htaccess files.
Any ideas?
Thank you!
You could try setting the TypoScript option config.absRefPrefix to /domain/www.example.com/
See http://buzz.typo3.org/people/soeren-malling/article/baseurl-is-dead-long-live-absrefprefix/ and http://wiki.typo3.org/TSref/CONFIG
Related
My application webroot is like : /home/username/appname/public_html
I have created a subfolder under public_html and installed the wordpress there.
Like: /home/username/appname/public_html/subfolder
we used the below redirection code because we want to access the application like https://example.com/subfolder
RewriteEngine on
RewriteCond %{HTTP_HOST} example\.com [NC]
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^(.*)$ http://example.com/br/$1 [L,R=301,NC]
RewriteRule ^/?(.*)$ http://example.com/br/$1 [L,R=301]
so when user will access main domain example.com so req will be redirected to example.com/subfolder/
but now we want to access example.com/file.txt
but the problem is due to redirection it also redirecting
so how can I exclude this url example.com/file.txt from redirection to example.com/subfolder/file.txt
Please help us.
I tried to add these config but did not work for me
RewriteCond %{REQUEST_URI} !^/file\.txt$
OR
RewriteCond %{REQUEST_URI} !^example\.com\/file\.txt$
I did many way to do this, but always getting 404 error.
I want to redirect subdomain
[username].domain.com/
to
domain.com/user/[username]/index.php
and the url on browser address is not changed still
[username].domain.com/
[username] is dynamic according to registered user in my site.
my last trial httaccess setting is
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(^.*)\.domain\.com$
RewriteRule ^ ^.domain.com/user%{REQUEST_URI} [L,P]
Note: I did set my DNS wildcard *.domain.com
Thanks in advance,
Nanang K
============================================================
SOLVED
I had to create 3 htaccess files.
in root directory (redirect to user)
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(^.*)\.domain.com
RewriteRule ^(.*)$ /user/$1 [NC,L]
in user directory (redirect to username_folder)
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^([aA-zZ])$ user/$1/index.php
RewriteCond %{HTTP_HOST} ^(^.*)\.domain.com
RewriteRule (.*) user/%1/index.php
in username_folder directory (rewrite the url into original url)
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^([aA-zZ])$ index.php?siteName=$1
RewriteCond %{HTTP_HOST} ^(^.*)\.domain.com
RewriteRule (.*) index.php?siteName=%1
now, when user access robert.domain.com, he will get the content from domain.com/user/robert/index.php. And the url browser still robert.domain.com
hope helps someone who get similiar problem.
Hello Can you please try this :-
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(.*)\.domain\.com$ [NC]
RewriteRule ^(.*)$ /users/$1 [L,NC]
It may use helpful.
It should be like this, try it out.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^[username].domain.com$
RewriteRule ^/?$ "http\:\/\/domain\.com\/users\/" [R=301,L]
hope this helps!
My server has several system folders and files by default. so for better overview I want to put my website in a subfolder like this:
www.domain.de/web/index.html
ALL links and website-related stuff is found in this subfolder "web". BUT the folder "web" should not be seen in the url!
I got this with these lines in my htaccess and it works:
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.de [NC]
RewriteCond %{REQUEST_URI} !^/web/.*$
RewriteRule ^(.*)$ /web/$1
But now the problem:
I also want other folder on my server to work. So www.domain.de/downloads/ should work, too. This folder is NOT in the subfolder "web". So if I write the direct url "www.domain.de/downloads" in my webbrowser, I don't want to get a redirect to "www.domain.de/web/downloads/", you know?
Is there any solution? :)
Thanks!
You Can use a RewriteCond to exclude your folder :
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.de [NC]
RewriteCond %{REQUEST_URI} !^/download [NC]
RewriteCond %{REQUEST_URI} !^/web/.*$
RewriteRule ^(.*)$ /web/$1
I am in a situation where an user can create his blog in a subdomain.
Users will create blogs and enter the address he wants like say,
abcd.domain.com Then my php code creates a directory called abcd.
To view the blog user will type in abcd.domain.com in his browser and I want a .htaccess code which will rewrite the url and open the files inside the domain.com/abcd
But for the user the url in the browser should stay abcd.domain.com
Currently I am trying this code
RewriteCond %{HTTP_HOST} ^test\.domain\.com$
RewriteCond %{REQUEST_URI} !^test/
RewriteRule ^(.*)$ /test/$1 [L,QSA]
But this gives me 404 even though I have a file test.html inside the test folder and trying to view that page.
Also in this situation I will have to manually make change to the .htaccess file for URL rewrite. What I want to know is if it is possible to have a wild card subdomain redirect to the respective directory.
You can use:
RewriteCond %{HTTP_HOST} ^test\.domain\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/test/
RewriteRule ^(.*)$ /test/$1 [L,QSA]
REQUEST_URI with leading /.
With wild card subdomain:
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^(.+)\.domain\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/%1/
RewriteRule ^(.*)$ /%1/$1 [L,QSA]
Note that it takes more than a rewrite rule to have wildcard subdomains. Just fyi.
You need to have created a wildcard DNS record for subdomains and also tell apache to use any subdomain request by having a ServerAlias of *.domain.com in the apache config.
Then try your rule this way and see if it works for you.
RewriteCond %{HTTP_HOST} ^((?!www).+)\.domain\.com$ [NC]
RewriteCond %1::%{REQUEST_URI} !^(.*?)::/\1/?
RewriteRule ^(.*)$ /%1/$1 [L,QSA]
In the public_html folder which is the root folder of my main site thesite.com, I have this htaccess file:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^m\.thesite\.com$ [NC]
RewriteCond %{HTTP_HOST} ^blog\.thesite\.com$ [NC]
RewriteRule ^ - [L]
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} ^www\.thesite\.com [NC]
RewriteRule ^(.*)$ https://thesite.com/$1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^category/([^/\.]+)/([^/\.]+)/([^/\.]+)/?$ category\_product\_list.php?mid=$1&sid=$2&did=$3 [L]
RewriteRule ^category/([^/\.]+)/([^/\.]+)/?$ category\_product\_list.php?mid=$1&sid=$2 [L]
RewriteRule ^category/([^/\.]+)/?$ category\_product\_list.php?mid=$1 [L]
RewriteRule ^p/([^/\.]+)/([^/\.]+)/([0-9]+)/([0-9]+)/([0-9]+)/?$ product.php?id=$2&vid=$3&mid=$4 [L]
RewriteRule ^p/([^/\.]+)/([^/\.]+)/([0-9]+)/([0-9]+)/?$ product.php?id=$2&vid=$3 [L]
RewriteRule ^p/([^/\.]+)/([^/\.]+)/([0-9]+)/?$ product.php?id=$2 [L]
RewriteRule ^offer/(.*) product_offer.php?ind=$1
RewriteRule ^([^/\.]+)/?([^/\.]*)/?$ $1.php [QSA,L]
Here, am forcing non-www url as well as forcing https URL for the thesite.com. And I have two subdomains: m.thesite.com and blog.thesite.com.
Both are in separate subfolders inside public_html.
The m.thesite.com is in /public_html/m.thesite.com/ folder. And it has this htaccess file:
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} ^www\.m\.thesite\.com [NC]
RewriteRule ^(.*)$ https://m.zapteka.com/$1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^category/([^/\.]+)/([^/\.]+)/([^/\.]+)/?$ category\_product\_list.php?mid=$1&sid=$2&did=$3 [L]
RewriteRule ^category/([^/\.]+)/([^/\.]+)/?$ category\_product\_list.php?mid=$1&sid=$2 [L]
RewriteRule ^category/([^/\.]+)/?$ category\_product\_list.php?mid=$1 [L]
RewriteRule ^p/([^/\.]+)/([^/\.]+)/([0-9]+)/([0-9]+)/([0-9]+)/?$ product.php?id=$2&vid=$3&mid=$4 [L]
RewriteRule ^p/([^/\.]+)/([^/\.]+)/([0-9]+)/([0-9]+)/?$ product.php?id=$2&vid=$3 [L]
RewriteRule ^p/([^/\.]+)/([^/\.]+)/([0-9]+)/?$ product.php?id=$2 [L]
RewriteRule ^([^/\.]+)/?([^/\.]*)/?$ $1.php [QSA,L]
RewriteRule ^offer/(.*) product_offer.php?ind=$1
For this subdomain also, I need to force https urls as well as non-www urls.
It seems to be working for the main site. I mean thesite.com. But when I try to access the m.thesite.com, it seems to be internally redirecting to the files of thesite.com instead of the m.thesite.com. I mean the url is being shown as https://m.thesite.com/ but the pages are from https://thesite.com
I have been trying to debug the issue for several hours now. Probably it could be something small that I missed. Any ideas?
BTW, thesite.com is having Wildcard SSL installed.
EDIT
Am sorry if my explanation was confusing. When I said url is showing as https://m.thesite.com/ but the content is from https://thesite.com/, I meant to say that in browser the url is shown as https://m.thesite.com. But the template file contents where from the desktop version of the main site thesite.com. The m.thesite.com is mobile version of the site. The pages that displays the contents where separate in both the desktop and mobile version of the site.
Like you see in the htaccess code that I included above, there is some PHP files inside the /public_html/ folder for the desktop version. All the files for the mobile version of the site is in /public_html/m.thesite.com/ folder.
So, in short, when I try to access the https://m.thesite.com/, it is displaying the index.php page from /public_html/index.php instead of /public_html/m.thesite.com/
So that's how I found that there's issue in the routing.
EDIT
VirtualHost entries fetched by using this command /usr/local/apache/bin/httpd -S:
I have also checked the Apache version and saw that it's 2.2.27 using the command: httpd -V
So I tried adding this line in the htaccess file:
RewriteLog "/logs/rewrite.log"
RewriteLogLevel 9
But it was giving internal server error. So I tried this line instead also:
LogLevel mod_rewrite.c:trace8
That was also giving me internal server error when site is accessed. So I commented it out.