Change public_html directory .htaccess - apache

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.

Related

.htaccess file wont redirect to /public folder (laravel issue)

I have folder /var/www/html/project/himp and there is my laravel installation.
In /var/www/html/project is my landing page index.html and some css files.
Inside /himp folder I have .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
also in /himp/public folder I have also .htaccess:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
Now when I go to the domain.com/himp/public I get Laravel installation and startup screen but when I go to the domain.com/himp I get just folder views, so there is no redirection to public folder ...
Why? What can be a problem here? Please help.
Contrary to the pattern in RewriteRule (see "What is matched?"), the variable REQUEST_URI contains the full path, including /himp. So the condition should be either
RewriteCond %{REQUEST_URI} !/public
without a beginning of string anchor ^, or you must include the full path
RewriteCond %{REQUEST_URI} !^/himp/public

I would like to redirect the domain name to the server subdirectory

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]

.htaccess if subdomain show www.site.com/subs/. no redirect url must bu sub.site.com

I have problem with .htaccess.
I need:
if $_SERVER["HTTP_HOST"] is sub.site.com must show content from www.site.com/sub/. But URL must be like sub.site.com.
And if sub.site.com/content/ must show content from www.site.com/sub/content/
Is it Possible?
Setting subdomains from hosting not working for me because of my CMS.
Try adding these rules to the htaccess file in your document root:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^sub.site.com$ [NC]
RewriteCond %{DOCUMENT_ROOT}/sub%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}/sub%{REQUEST_URI} -d
RewriteRule ^(.*)$ /sub/$1 [L]
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^sub\.site\.com$ [NC]
RewriteRule (?!^sub/)^(.*)$ /sub/$1 [L,NC]

How can I remove "index.php" from my links?

Normally I access a page like this: http://localhost/codeigniter/index.php/auth/login
However I want to be able to access to the page like this : http://localhost/codeigniter/auth/login
I have no information about http.conf and .htaccess configurations.
I have set $config['index_page'] = ''; in codeigniter/application/config/config.php
my http.conf file is at its default except uncommentnig "LoadModule rewrite_module modules/mod_rewrite.so"
I inspected many proposed .htaccess files but I could not understand the logic behind the rewriting rules.
Here is the most successful .htaccess content for me. It is located at /www/CodeIgniter/ .
(by the most successful I mean that this is the only one that gives 404 error created by the CodeIgniter not by the server.)
RewriteOptions Inherit
Options -Indexes
Options +FollowSymLinks
RewriteBase /CodeIgniter/
# Set the default file for indexes
DirectoryIndex index.php
<IfModule mod_rewrite.c>
# activate URL rewriting
RewriteEngine on
# do not rewrite links to the documentation, assets and public files
RewriteCond $1 !^(images|assets|uploads|captcha)
# do not rewrite for php files in the document root, robots.txt or the maintenance page
RewriteCond $1 !^([^\..]+\.php|robots\.txt)
# but rewrite everything else
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
ErrorDocument 404 index.php
</IfModule>
I hate requesting direct solutions however unfortunately, it is my last resort :/
Can you give me a right solution to my problem?
It's my repeat answer:
Codeigniter issues with paths in localhost (XAMPP)
please create .htaccess file in project folder and write:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite all other URLs to index.php/URL
RewriteRule ^(.*)$ index.php?url=$1 [PT,L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 index.php
</IfModule>
You don't need to define in base_url in config file:
$config['base_url'] = ''; // blank it.
put this on your htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
</IfModule>
make sure the rewrite module is enabled on your server
This is the simplest one i found which works for me :-
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

.htaccess to mask url and redirect domain name to subdirectory

Hi folks
I'd appreciate some .htaccess advice.
I have two wordpress installations. "A" which is in my ISP's Linux server root directory and "B", which is in a subdirectory of the same server called "directoryB".
Actual structure is:=
A.com
A.com/directoryB/
I own two domain names A.com and B.com. I want people to use the address B.com when accessing everything on directoryB, not A.com/directoryB/.
I want to leave the "real" "A" alone - no redirections!
I have been assured this can be done using the .htaccess file, but I've failed so far!
I have managed to "mask" the home page of "B" using cPanel, but it reverts back to A.com/directoryB/ once you move away from the home page. I'm also not sure if the .htaccess ought to be in the root or subdirectory.
All I want is to mask the A.com/directoryB/ with B.com/ every time it appears on the address bar......
Thanks in advance for any help!
Put this in a .htaccess file in directoryB and see if it works:
RewriteCond %{HTTP_HOST} !^B.com$ [NC]
RewriteRule (.*) http://B.com/$1 [R=301,L]
Put this in .htaccess in your root directory -
Options +FollowSymlinks
<IfModule mod_rewrite.c>
RewriteEngine on
Redirect permanent /directoryB http://B.com
</IfModule>
The htaccess in public_html is:-
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
Redirect permanent /directoryB http://B.com
RewriteRule ^test/([^/]*)/$ /test/login/?id=$1
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Options -Indexes
=============== this is the htaccess from "directoryB"
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /directoryB/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /directoryB/index.php [L]
</IfModule>
# END WordPress
Options -Indexes