Different URL's / Same Server - .htaccess

)
One server - multiple URl's coming in to it. In the root there is an htaccess file that handles the traffic and sends it to subfolders ... badly.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^XXXXX.com$ [NC]
RewriteRule ^((?!XXXXX).*)$ /XXXX/$1 [NC,L]
How would I go about altering this so that all requests starting with "XXXXX.com" start looking in the folder "myserver.com/XXXXX" and the url in the browser stays "XXXXX.com"??
It currently only works for files in the root of that folder - as soon as you click a link to another file within that folder (or subfolders) the URL goes back to being the main server URL.
Any help greatly appreciated :-)

Try with:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^XXXXX.com$ [NC]
RewriteRule ^((?!XXXXX/).*)$ /XXXXX/$1 [NC,L]
Because it missed a / (after XXXXX in test RewriteRule uri). That was ok for root, but not for others.

Related

Redirect to old images folder, from new "root" folder

STATUS
The client has a site visible at client-domain.com, inside the root there is an .htaccess
RewriteEngine on
RewriteCond %{REQUEST_URI} !v2/.*
RewriteRule ^(.*)$ v2/$1 [L]
...and some folders:
v0 (with a page for temporary shoutdown the server)
v1 first version
v2 actual version of website
GOAL
Create a new website on v3, but keeping some asssets of version v2
(there is a big folder with subfolders in client-domain.com/assets/prjimg/ that obviously pointing at root/v2/assets/prjimg.
I can't move the folder, I don't have ssh access... I'd like to add a line to the new .htaccess without create a mess for pointing on v3 the website but v2 all the link at that subfolder 'prjimg')
All website --> root/v3/
but /assets/prjimg --> root/v2/asstes/prjimg
RewriteEngine on
RewriteCond %{REQUEST_URI} !v3/.*
*** something here? ***
RewriteRule ^(.*)$ v3/$1 [L]
I look for but doesn't find yet the solution, sometimes 500 eorr, sometimes loop...
Thanks
You may use these rules in site root .htaccess:
RewriteEngine on
# /assets/prjimg/ goes to /v2/
RewriteRule ^assets/prjimg(/.*)?$ v2/$0 [L,NC]
# everything else goes to /v3/
RewriteRule !^(v2|v3)/ v3%{REQUEST_URI} [L,NC]

Use htaccess to redirect root but still have directory listing accessible with a backdoor

What I thought I was trying to do was genius, but it seems to not work properly.
I have a public subdomain with temp files on it. I don't want people to be able to see all the files listed when they visit it. I don't want to password protect it because that will mess up several scripts when fetching files off the server, and I don't want a blank index.html there to stop listing because I want to be able to see the listing.
So my stroke of genius was to have a .htaccess file like so:
RewriteEngine On
RewriteCond %{REQUEST_URI} !/#dir
RewriteCond %{REQUEST_URI} !/?show=dir
RewriteRule ^$ http://example.com/ [nc]
My theory was that visiting files.example.com would redirect to example.com but visiting files.example.com/?show=dir or files.example.com/#dir would not; and obviously since ?show=dir does nothing it would list all my files as normal.
My RewriteConditions have no effect though.
Is this possible?
First, you can't match against URL fragments (the #dir part) because that doesn't ever get sent to the server. It's a client side only thing.
Second, you can't match against the query string (the ?show=dir part) in the %{REQUEST_URI} variable, you need to use %{QUERY_STRING} instead.
So try:
RewriteEngine On
RewriteCond %{QUERY_STRING} !^show=dir$
RewriteRule ^$ http://example.com/ [nc]

Load new site from subdirectory as index

I want to load my new website from subdirectory including default index.html page.
In my public_html, I have /oldsite/ and /newsite/ folders...
Then.. When I access to http://www.mysite.com/.. i want it to load all contents from http://www.mysite.com/newsite/ without redirecting. I want to do it with .htaccess mod_rewrite if possible..
Can anybody help me out with this. How to do this?
# to ensure that server already know that you going to use mod-rewrite
RewriteEngine on
# if the request from http is mysite.com or www.mysite.com go to next line (else abort)
RewriteCond %{HTTP_HOST} ^(www.)?mysite.com$ [NC]
# if the request destination is not the folder /newsite go to next line
RewriteCond %{REQUEST_URI} !^/newsite/
# if the requested name is not an existed file in public_html directory
RewriteCond %{REQUEST_FILENAME} !-f
# if the requested name is not an existed directory in public_html directory
RewriteCond %{REQUEST_FILENAME} !-d
# forward request to /newsite/
RewriteRule ^(.*)$ /newsite/$1
# if the request domain is mysite.com (with out any string afterward), go to next line
RewriteCond %{HTTP_HOST} ^(www.)?mysite.com$ [NC]
# forward request to the default file under newsite directory
RewriteRule ^(/)?$ newsite/ [L]
It is generally not a good idea to deploy a website like this. Instead you should create virtual hosts for the live and development versions of your site. If you can't do that with your current hosting provider you can make use of symlink for public_html and when the new version is ready to go live just change its path. Hope that helps.

htaccess command to prevent master site access via subdirectory?

I have hosting setup with a master domain (mapped to the web root) and then a number of addon domains (each with their own folder within the web root). At the moment you can visit www.masterdomain.com/addondomainsubdir and reach the same page as you would if you visited www.addondomain.com (which maps to /public_html/addondomainsubdir). I want to prevent this so if you visit www.masterdomain.com/addondomainsubdir then it will do a 301 redirect to www.addondomain.com. The new addondomain.com site is a single page site so it does not have to map any additional pages.
Adding rules to the htaccess file in the web root does notaffect anything as the subdir exists which is wierd as i thought the htaccess command should work even if there is a matching subdir (i've tried the following which works when there's no matching subdir):
RewriteRule ^addondomainsubdir?$ http://www.addondomain.com [NC,R=301,L]
Logically given it's reaching this directory I figure i need to add a command within the htaccess file in the addondomainsubdir directory however nothing appears to have any effect (i've got various other rules setup and they work fine).
I would be massively grateful if anyone explain the best way to rectify this?
Thanks so much for your help,
Dave
I know this is an old post, but it has never been successfully answered. So for all of you finding this via search, this should do what the OP is asking.
Add this line to your .htaccess file:
redirect permanent /addondomainsubdir/ http://www.addondomain.com
Try these rules in your .htaccess:
Options +FollowSymlinks -MultiViews
RewriteEngine on
# for http
RewriteCond %{HTTP_HOST} ^(www\.)?masterdomain\.com$ [NC]
RewriteCond %{SERVER_PORT} =80
RewriteRule ^([^/]+)/?$ http://www.$1.com/ [R=301,L]
# for https
RewriteCond %{HTTP_HOST} ^(www\.)?masterdomain\.com$ [NC]
RewriteCond %{SERVER_PORT} =443
RewriteRule ^([^/]+)/?$ https://www.$1.com/ [R=301,L]
Instead of putting a rule in your main .htaccess, I would make make a .htaccess for each add-on domain, putting each one in the respective subdirectory.
RewriteEngine on
RewriteCond %{HTTP_HOST} masterdomain\.com$ [NC]
RewriteRule ^addondomainsubdir(.*)$ http://www.addondomain.com/$1 [R=301,L]

Cannot remove index.php from my urls in Codeigniter

I am using codeigniter and when I set up the website I added necessary code in my .htaccess file to remove index.php (default) from my urls. I just happened to replace my public_html folder from a back up file of my website. Since I did that, I cannot get any of the links on home page to work unless insert index.php in the url between the domain name and the rest of the url as in http://www.obsia.com/index.php/contact/ instead of http://www.obsia.com/contact/ and it works. So, in my config file within the application folder, I changed
$config['index_page'] = "";
to
$config['index_page'] = "index.php";
and all the links seem to work now. But how do I remove index.php from the URLs.
Here is what my .htaccess code looks like:
RewriteEngine on
RewriteBase /
RewriteCond $1 !^(index\.php|public|user_guide|robots\.txt|css)
RewriteRule ^(.*)$ /index.php?/$1 [L]
Can anyone point me in the right direction. It will much appreciated.
Regards,
G
What yo want to do can be done this way:
RewriteEngine on
RewriteBase /
# Static content. Rewrite to - (don't change) and mark as last rule.
RewriteRule !^(index\.php|public|user_guide|robots\.txt|css) - [L]
# Do the rewrite.
RewriteRule ^(.*)$ /index.php?/$1 [L]
However, a slightly better way of doing that is this:
RewriteEngine on
RewriteBase /
# Only do the rewrite under the condition that the requested URL isn't a (real) file.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /index.php?/$1 [L]
there are so many ht access files... In my case i was editing the wrong file... u should edit the file that is inside the project.. for example i work on code igniter and project name was test , so inside test folder i had a htaccess file and inside my application folder ie test/application there was another htaccess file.. i was editing the access file inside the application folder, but i had to edit the file in test folder not test/application/.htaccess.... hope sum 1 finds this useful.. cos i spent half a day to figure this out :(
Cheers
ksp

Resources