I just want to remove the subdirectory from the URL but I still want the root directory to be accessible and even fetch the index.php from root when I go directly to the page.
I am currently using the following code:
RewriteCond %{HTTP_HOST} ^(www\.)?website\.com$
RewriteRule !^backup/ /backup%{REQUEST_URI} [L]
But this treats the subdirectory like its root.
Thanks
Related
I need to redirect all the 404 errors inside a folder to a file in the root.
i make an example to explain better:
I have a directory www.site.com/join-us/ where I have some files for the positions available: www.site.com/join-us/positon1.php, www.site.com/join-us/positon2.php
from time to time I have to delete some of these positions/files, so I would like to redirect all this 404 errors inside the /join-us/ directory to a specific file www.site.com/join-us.php
is it possible?
In htaccess in the document root :
RewriteEngine on
RewriteCond %{DOCUMENT_ROOT}/join-us/$1 !-f
RewriteRule ^join-us/(.+)/?$ /join-us.php [NC,L]
This will internally redirect /join-us/notfountfile to /join-us.php
i'm working on a drupal7 multisite setup based on subdirectories where example.com is used for the main website and example.com/subsite is another standalone drupal install. subsite is a symlink located in the root directory and also pointing to the root directory to give the subsite access to drupal core files.
now i have to make static content available via example.com/subsite/static, so i created a directory static in the root directory. that all works fine.
the problem is, that example.com/static is now also accessable and i want to prevent that.
i tried to redirect all requests to /static to /subsite/static resulting in inconsistent behaviour and redirect loops.
directory structure:
/
/{various drupal directories}
/subsite -> /
/static
rewrite rule:
RewriteRule ^/static/(.*)$ /subsite/static/$1 [R,L]
thx in advance
Is this what you want?
RewriteBase /
RewriteRule ^static/(.*)$ /subsite/static/$1 [L,R=301]
RewriteRule ^subsite/static/(.*)$ /static/$1 [L]
In the first line we redirect all call to /static/ to /subsite/static/.
In the second line we rewrite all call to /subsite/static/ to /static.
If it doesn't work please post your whole .htaccess file.
i fixed the redirect loops by using a rewrite condition, should have thought of that before.
RewriteCond %{REQUEST_URI} !^/subsite/(.*)$
RewriteRule ^static/(.*)$ /subsite/static/$1 [L,R=301]
thx anyway #florian-lemaitre for trying to help me
I have a second website stored in the root of my main website. It's a subdomain with its own URL
I want users to access the second website via a URL eg
www.mysecondwebsite.com
but not via the first website eg
www.myfirstwebsite.com/mysecondwebsite
Can this be done via .htaccess? If so where do I put the .htaccess file: in the root of the main site or the root of the subdirectory/domain?
Thank you.
At the top of the htaccess file in your mysecondwebsite folder, add this:
RewriteEngine On
RewriteCond %{HTTP_HOST} !mysecondwebsite\.com$ [NC]
RewriteRule ^ - [L,R=404]
You can also replace R=404 with F if you'd rather return a 403 Forbidden.
using the htacces I want to redirect my url to a directory, which I am using this for:
RewriteEngine on
RewriteRule !^dir1/(.*) /dir1/$1
It works great for scrips but not for images.
I was also wondering if there is a way to only rewrite if a directory doesn't exists in the root.
example:
mysite.com redirects to: mysite.com/dir1
but mysite.com/dir2 doesn't redirect if dir2 exists in the root.
I know its a little confusing. thanks for the help!
This is what I use for that:
# Redirect if root folder doesnt exist (request_uri must begin with a dir (contain slash or contains only alphanum plus -))
RewriteCond %{DOCUMENT_ROOT}/$1 !-d
RewriteRule ^([a-z0-9-]+)(/(.*))?$ /dir1/$0 [NC,L]
I'm trying to organise my websites with .htaccess, and I want to following configuration:
The URL of the main site has to be beta.example.com/portal/
The other sites should be in beta.example.com/othersite/
If users go to beta.example.com, they should be redirected 301 to
beta.example.com/portal/
beta.example.com/portal (without the trailing slash) should redirect to beta.example.com/portal/
/portal/ is not a physical file path on the server. I want all these sites to
be in a folder together, say /html/www/websites/
The folder the portal resides in, should not be located in
/html/www/websites/portal/, but I want to be able to switch the live
site to a new version (in a different folder) on the server, quickly,
invisible, without any downtime. This goes for all sites by the way.
I'm currently working with two or three .htaccess files: one in the root (www.), which directs beta.example.com to the folder /websites/
#RewriteBase / #should I use rewritebase or not?
/RewriteCond %{HTTP_HOST} ^beta.example.com$
RewriteRule (.*) websites/$1 [L,NC]
A .htaccess file is in the folder /websites/, and maybe another one or maybe not in the folder a site resides in.
RewriteBase /websites # or, not...
# rewrite the active site to the folder /portal_v1.0/
RewriteCond %{REQUEST_URI} ^/portal/
RewriteRule (.*) portal_v1.0/$1 [L]
# rewrite the root to /portal/
RewriteRule ^$ http://beta.example.com/portal/ [L,NC]
However, I still can't get this to work exactly the way I want. One problem is what beta.example.com/portal redirects to www.example.com/websites/portal/ , I don't want that. Help! Thanks in advance!