Remove directory from URL - .htaccess

I want to remove a directory from my homepage link
example.com/remove/ to example.com
thing is, the index is located in the "remove" directory.
I've tried:
RewriteRule ^front /(.*)$ /$1 [L,R=301]
But this produced an internal server error

If you have access to httpd.conf change this in httpd.conf
DocumentRoot "C:/xampp/htdocs/remove"
If you are running xampp or having a linux setup you will find httpd.conf in conf folder which is having below line in which you have to add your remove directory which will be your new root directory then every call to example.com will forwarded to example.com/remove.
And then restart your server.
Or if not use this in .htaccess
DirectoryIndex index.html
RewriteEngine on
RewriteCond %{REQUEST_URI} !remove/
RewriteRule ^(.*)$ /remove/$1 [L]

Related

Restricting RewriteRule to ignore certain folders

I have a basic Rewrite rule defined in the root of my website, in an .htaccess file:
<IfModule mod_rewrite.c>
# http://www.generateit.net/mod-rewrite/index.php
# Tell PHP that the mod_rewrite module is ENABLED.
SetEnv HTTP_MOD_REWRITE On
RewriteEngine on
RewriteRule ^([^/]*)/$ category.php?cat=$1 [L]
RewriteRule ^([^/]*)/([^/]*)/$ post.php?cat=$1&post=$2 [L]
RewriteRule ^blog-([^/]*).php$ default.php?page=$1 [L]
</IfModule>
I have 2 sites hosted on the same folder structure:
DIR: example2.com
file: category.php
file: default.php
file: post.php
So the rewrite rule will redirect e.g.
example.com/post.php?cat=general-ledger&post=gl-journals-volumes
to:
example.com/general-ledger/gl-journals-volumes/
However, I have installed Wordpress in a folder called ddc on example2, but when I visit:
example2.com/ddc/wp-admin/user/
I can't view it, as the system thinks it's trying to view a rewritten page.
Is there any way I can stop the rewrite rule from firing for specific directories?
I have tried:
RewriteCond %{REQUEST_URI} !^/(example2.com|ddc)/?(.*)$ [NC]
But it made no difference. Furthermore, the error log shows this when I try to access the folder:
[Mon Jan 16 22:39:53.365334 2017] [autoindex:error] [pid 28997]
[client my_ip_address_here:53652] AH01276: Cannot serve directory
/home/oracle36/public_html/example2.com/ddc/wp-admin/user/: No
matching DirectoryIndex (default.php) found, and server-generated
directory index forbidden by Options directive
Your rewrite rules are not the problem. They only affect URLs with directories of one or two levels. Your problem is that you don't have index.php set up as a directory index, so there is nothing for Apache to serve from the WordPress directory. Add this to your .htaccess:
DirectoryIndex default.php index.php
I am adding default.php to that because the error message shows you have that set up already, and then adding index.php to it as another option, to support WordPress. You can remove your RewriteCond.

Telling ftpsync to ignore directories in public_html

In ftpsync, when I try to update my site example.com, I find ftpsync deletes everything in public_html (where example.com resides). My host specifies that other domains reside as subdirectories in public_html.
Even though I have tried telling ftpsync to ignore public_html/subdir-example1.com and the code shown below it gets removed every time I try an update.
{
"local":"public/",
"remote":"public_html/",
"host":"example.com",
"port":21,
"user":"secret",
"pass":"secret",
"connections":"1",
"ignore":[
".htaccess",
"subdir-example1.com/",
"subdir-example2.com/"
]
}
So how do I tell ftpsync to ignore a directory on the host?
ftpsync says it basically nukes the entire directory on the other server. So the workaround is to create a subdirectory in public_html, then change the remote in config.json to be public_html/subdirectory/maindomain.com
Then change .htaccess following instructions written by BlueHost:
# BlueHost.com
# .htaccess main domain to subdirectory redirect
# Do not change this line.
RewriteEngine on
# Change example.com to be your main domain.
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
# Change 'subdirectory' to be the directory you will use for your main domain.
RewriteCond %{REQUEST_URI} !^/subdirectory/
# Don't change the following two lines.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Change 'subdirectory' to be the directory you will use for your main domain.
RewriteRule ^(.*)$ /subdirectory/$1
# Change example.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 site, index.php, index.html, etc.
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteRule ^(/)?$ subdirectory/index.html [L]
https://my.bluehost.com/cgi/help/347#redirect

How to always redirect to subfolder using htaccess

I want to redirect visitors who are viewing index (not other files) to a sub folder in every conidition. At the moment I'm using the code below in my .htaccess file:
<IfModule mod_rewrite.c>
RewriteRule ^$ /dir [L,R=301]
</IfModule>
But it only works on the main domain but doesn't work when we have the script itself in a subfolder. How should I modify this code to works everywhere?
The previous code works like below when installed on the root folder:
http://www.domain.com => http://www.domain.com/dir
Which is fine, but when we have it on sub, it works like below:
http://www.domain.com/sub => http://www.domain.com/dir
That means it move one level up and then locate for dir and that's the failure.
Use that:
# Change in subfolder:
RewriteBase /sub/
RewriteRule ^$ dir [L,R=301]
In root .htaccess for each subfolder:
RewriteRule ^([^/]+)/$ $1/dir/ [L,R=301]

.htaccess rewrite and subdomains connected to subdirectories

I have installed wordpress to my public_html/ folder on my host. Now, I want to help my friend to get his own wp blog. I wanted to add a folder public_html/zoran/ where I wanted to install another wp and to add subdomain zoran.example.com to call that folder.
Problem is that .htaccess from public_html/ (my wp installation) is messing .htaccess inside public_html/zoran/ folder. I googled a lot, and figured out that this is impossible to have one .htaccess rules in root folder and other in subfolder (mod rewrite).
I cannot access my cPanel for couple of days now, and it will be unavailable for a few days, I recieved mail about that.
Now, I am at this point. I have moved my wp into public_html/www/ and I stored .htaccess file into public_html/ with following content:
# Rewriting conditions
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule (.*) http://www.example.com/ [R,L]
# Identify subdomain as %1
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com
# Check if %1 is directory
RewriteCond %1 !-d
# rewrite the request to the subdomain's subfolder
RewriteRule (.*) %1/$1 [L]
Above code redirects example.com to www.example.com, and also, it opens my wp, stored in public_html/www/. But, when I try to go to zoran.example.com, I get 500 error, and that folder has just index.html file in it.
What is happening? How come that www folder works, and folder zoran does not work on same principle?!

.htaccess redirect to subdirectory without changing url

I have the site
www.site.com
I would like the root directory to read from the /en subdirectory
WITHOUT changing the url to
www.site.com/en on the address bar
Putting this in the .htaccess file in your root directory should do the trick, assuming of course mod_rewrite is installed and enabled, and AllowOverride All is set in the VirtualHost of the conf file. It won't change the address bar.
RewriteEngine On
RewriteRule ^(.*)$ en/$1 [L, NC, QSA]

Resources