I have scratching my head over it for a long time now. Can't manage to get it to work. (I am a noob with apache that can be one reason also). Ok here is the problem in nutshell. I am using wamp and I have a directory Retailer. There is another directory inside it which is called public that contains the index and otherfiles. I want to make this public directory document root. I want to achieve this with .htaccess
My Rewrite module for apache is turned on.
Here is what I have tried:
RewriteEngine on
RewriteBase /public/
RewriteRule ^index.php$ test.php
And also I have tried
RewriteEngine on
RewriteCond %{HTTP_HOST} ^localhost/Retailer$ [NC,OR]
RewriteCond %{HTTP_HOST} ^localhost/Retailer$
RewriteCond %{REQUEST_URI} !public/
RewriteRule (.*) /public/$1 [L]
And I have tried
RewriteEngine on
RewriteCond %{HTTP_HOST} ^http://localhost/Retailer/$ [NC,OR]
RewriteCond %{HTTP_HOST} ^http://localhost/Retailer/$
RewriteCond %{REQUEST_URI} !public/
RewriteRule (.*) /public/$1 [L]
But result in all these cases is the same. That is:
Any help will be appreciated
Ahmar
Use this rule in your Retailer/.htaccess file:
RewriteEngine on
RewriteBase /Retailer/
RewriteRule ^((?!public/).*)$ public/$1 [L,NC]
You should config this not in .htaccess file but in apache config file httpd.conf:
<VirtualHost 127.0.0.1:80>
DocumentRoot "/path/to/project/Retailer/public"
ServerName "retailer.local"
ServerAlias "www.retailer.local"
</VirtualHost>
Also you need to update your hosts file with the next line:
127.0.0.1 retailer.local
And restart your web server!
Related
I would like to redirect the domain name to the server subdirectory by using apache rewrite rules .How could I change the .htaccess file?
www.a.com bound to /a
www.b.com bound to /b
I could not change httpd-vhosts.conf because some Cross-domain issues.
The /d has a .htaccess file ,i would caught the 404 error if i deleted it,or I would caught the ERR_TOO_MANY_REDIRECTS .
The .htaccess file:
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
</IfModule>
Here it is: (save as .htaccess on your website's root)
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.(.*)\.com$
RewriteRule ^(.*)$ /full/path/to/document/root/%1/$1 [END]
Website root, is the DocumentRoot defined on your apache2/vHost config.
You said you want www.a.com redirects to /a, DocumentRoot is the full system path to URL path /
This will work on Apache 2.4, NOT 2.2.
Reply to the first comment:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.(a|b|c).com$
RewriteRule ^(.*)$ /full/path/to/document/root/d/$1 [END]
RewriteCond %{HTTP_HOST} ^www.(.*)\.com$
RewriteRule ^(.*)$ /full/path/to/document/root/%1/$1 [END]
I use this in my httpd.config and it works:
<VirtualHost *:80>
ServerName olddomain.com
ServerAlias www.olddomain.com
Redirect permanent /FolderName/Filename_with_underscores.html http://newdomain.com/some-folder-with-dashes/?lang=fr
Redirect permanent /FolderName/Other_filename.html http://newdomain.com/some-other-folder/?lang=fr
Redirect permanent / http://newdomain.com/
</Virtualhost>
Now I'd like to put this in the .htaccess file in the root of the website.
I have tried several things but it keeps failing.
Does anyone know how to translate this httpd redirect to .htaccess?
There are capitals, dashes and underscores in the url's...
The code below works (but it's only half the story: it redirects all (www.)olddomain.com to the desired folder at newdomain.com):
RewriteCond %{HTTP_HOST} ^olddomain\.com\$ [OR]
RewriteCond %{HTTP_HOST} ^www\.olddomain\.com$
RewriteRule ^/?$ "http://newdomain.com/some-folder-with-dashes/?lang=fr" [R=301,L]
Thnx
You can use in your root .htaccess:
RewriteEngine on
# All rules only for olddomain.com
RewriteCond %{HTTP_HOST} !^(www\.)?olddomain\.com$ [NC]
RewriteRule ^ - [L]
RewriteRule ^FolderName/Filename_with_underscores\.html$ http://newdomain.com/some-folder-with-dashes/?lang=fr [NC,R=301,L]
RewriteRule ^FolderName/Other_filename\.html$ http://newdomain.com/some-other-folder/?lang=fr [NC,R=301,L]
RewriteRule ^(.*)$ http://newdomain.com/$1 [R=301,L]
I would like to show my index.html file on address bar. When you go to http://www.example.com/ to redirect it to http://www.example.com/index.html and show that index.html on address bar.
EDIT
This is my .htaccess file. I have try neo example but with no luck.
DirectoryIndex naslovnica.php
Options -Indexes
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule .* 404.html [L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /naslovnica\.php
RewriteRule ^naslovnica\.php$ http://example.com/naslovnica.php [R=301,L]
You will have to look into Apache DocumentRoot Directory. Have a look at the following Apache Docs...
Apache DocumentRoot
You will have to create the index.html and put it in the DocumentRoot directory.
From the DOCS...
If your DocumentRoot "/usr/web" then an access to http://my.example.com/index.html refers to /usr/web/index.html.
Edited
The following document explains about hiding the index. Guess you can use it to unhhide the index as well.
Mod_Rewrite – Hide index.php
The following might be a start towards finding the right solution...
Options +FollowSymLinks
RewriteEngine on
# Redirect client requests for www.example.com/ to "www.example.com/index.html" in main doamin
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.html
RewriteRule ^index\.html$ http://www.example.com/index.html [R=301,L]
My folder for public_html is /domain.com/public_html/ but i want the htaccess to redirect them to the folder /domain/public_html/www/ but still have domain.com as domain and not domain.com/www .
EDIT:
I want the subfolder www in the public_html do be the default root and not public_html itself
Any solution on this?
Here is my current htacess
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ www/$1 [NC,L]
</IfModule>
If you can only go for .htaccess, this simple one should do it;
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/www/
RewriteRule ^(.*)$ /www/$1 [QSA]
Explanation;
RewriteEngine on # Turn on mod_rewrite functionality
RewriteCond %{REQUEST_URI} !^/www/ # Don't rewrite requests that are
# already to the /www/ directory.
# If this isn't here, we'll go into
# a neverending loop.
RewriteRule ^(.*)$ /www/$1 [QSA] # Rewrite all else to the www subdirectory
# QSA = keep the query string.
EDIT: Didn't see your existing htaccess, this (minus the redundant RewriteEngine statement) should probably go at the end instead of the whole IfModule block.
Try to put this in the htaccess on the public_html folder:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ www/$1 [NC,L]
</IfModule>
OR
Edit the apache configuration (httpd.conf)
vi /usr/local/apache/conf/httpd.conf
and set the DocumentRoot of the domain as
DocumentRoot /home/user/public_html/www
Save the file and restart the httpd service.
OR (recomanded)
Take a look at this question(and it's answer) - https://stackoverflow.com/a/5891858/1361042
EDIT
Use this HTACCESS:
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/www/
RewriteRule ^(.*)$ www/$1 [NC, QSA]
</IfModule>
don't add it to yours but replace your htaccess with this one.
I have a shared hosting with one domain and one sub-domain (for mobile and clients). Each domain and sub-domains has different default index pages. The hosting company told me to put everything in my .htaccess file since I don't have access to the httpd.conf.
What I want to do is this:
If a user goes to domain1.com the DirectoryIndex should be: index.html
If a user goes to mobile.domain1.com the DirectoryIndex should be: mobile-index.html
If a user goes to post.domain1.com the DirectoryIndex should be: post.php
If a user goes to vote.domain1.com the DirectoryIndex should be: vote.php
Edit:
In addition, if I go to domain1.com/page/ the DirectoryIndex should be: index.html. If I go to mobile.domain1.com/page/ the DirectoryIndex should be: mobile-index.html
What can I put in my .htaccess file in order to change the DirectoryIndex for each sub-domain?
Thank You very mich
<IfDefine> does not work like that. <IfDefine> only runs when apache starts. You should go with a mod_rewrite solution. view #tzakrajs answer.
You can use this in your .htaccess file:
SetEnvIf Host ^www\. page=www
SetEnvIf Host ^mobile\. page=mobile
rewriterule ^.*$ test.php?subdomain=%{ENV:page} [QSA,L]
Simply just configure all your sub-domain using SetEnvIf and then simply let the PHP do its magic.
Try this:
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^domain1.com$
RewriteRule ^.*/$ index.html [R=302,L]
RewriteCond %{HTTP_HOST} ^mobile.domain1.com$
RewriteRule ^.*/$ mobile-index.html [R=302,L]
RewriteCond %{HTTP_HOST} ^post.domain1.com$
RewriteRule ^.*/$ post.php [R=302,L]
RewriteCond %{HTTP_HOST} ^vote.domain1.com$
RewriteRule ^.*/$ vote.php [R=302,L]
You can set using just oyur .htaccess file like this:
RewriteCond %{HTTP_HOST} ^(www\.)?domain.com$ [NC]
RewriteRule DirectoryIndex index.html
RewriteCond %{HTTP_HOST} ^mobile.domain.com$ [NC]
RewriteRule DirectoryIndex mobile-index.html
...