I have a cakePHP app working at http://domain1.com/domain2, and want to point http://domain2.com/ to this application.
I have done this change the document root of domain2 to public_html/domain2, but, when I go to: domain2.com all css, javascript and images are not loaded, with a message saying controller not found.
What I can do?
All domains have a folder with their domains without the TLD at domain1.com, I think if I create a htaccess and get the domain without TLD, and finally change rewriteBase, will work as expected, but don't know how to do this.
Current htaccess of domain2:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
You can try adding an htaccess file in domain2's document root with the following rules:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} \.(css|js|png|jpe?g|gif|bmp|ico)$ [NC]
RewriteRule ^/?domain2/(.*) /$1 [L,PT]
This should remove the domain2 part of the links.
Related
I have a wordpress website physically located in the "wordpress" subfolder of the root folder of the website. I manage to hide the subfolder "wordpress" in the URL with the following code:
.htaccess on root folder
RewriteEngine On
RewriteBase /
RewriteRule ^$ wordpress/ [L]
RewriteRule ^(.*)$ wordpress/$1 [L]
.htaccess in wordpress subfolder
RewriteEngine On
RewriteBase /wordpress/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [L]
However, I have another website in another subfolder let's call it "other-wp" and this needs to remain as it is, with the URL pointing to:
https://mywebsite.com/other-wp/
Since I managed to hide the "wordpress" folder in the URL, I am unable to acces my "other-wp" it says the page doesn't exist.
I'm not skilled with coding for .htaccess so i don't know what i need to do to fix it.
Could you help?
You need to implement an exception for that second resource:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/other-wp
RewriteRule ^/?(.*)$ /wordpress/$1 [L]
I also made some other modifications to that top level configuration file, just smaller optimizations. In general you should check if you can place such global rules in the actual http server's host configuration. Using distributed configuration files (".htaccess") is just a fallback if you have no access to the real configuration. They work, but come with disadvantages.
I am Hosting a domain on free hosting site 000webhost, I want to redirect all files or folder that doesn't exist to my homepage. The Code, I have used is:
RewriteEngine on
rewritecond %{http_host} ^domain\.com$ [nc]
rewriterule ^(.*)$ http://www.domain.com/$1 [r=301,l]
RewriteCond %{THE_REQUEST} ^.*/index.html
RewriteRule ^(.*)index.html$ http://www.domain.com/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.html
It works, but the url doesn't change to homepage. Like if I am trying to open www.domain.com/blaa it redirects me to home page but the URL is still www.domain.com/blaa. I want it to be changed to www.domain.com.
If I am trying to open a valid directory, which exist in my root folder, it also redirects to homepage. Like if I am trying to open www.domain.com/folder, it should result in files and directories in that folder, instead of that it redirects me to homepage and web address is still same like www.domain.com/folder.
Also I want to keep using the above 2 rules to open website with WWW and index.html with www.domain.com
Please help me.
Thanks in advance.
As per your questions's title, to redirect to homepage if the request is not for a file or dir, you can use :
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ / [L]
You can also use ErrorDocument directive to rewrite non-existent requests to homepage
ErrorDocument 404 /
I am trying to make test env for this website. I have the same website on live and it is working.
I am trying to redirect the request to do the redirect to this usbfolder(OPS).
This is what I wrote so far but it sounds it is redirecting to root.
If I remove the https it works but with https it doesn't. It sounds it's redirected to root
RewriteEngine on
RewriteBase /OPS/
RewriteCond %{HTTP_HOST} ^dev.domain\.co\.uk$
RewriteCond %{REQUEST_URI} !^/OPS/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /OPS/$1 [L]
RewriteCond %{HTTP_HOST} ^dev.domain\.co\.uk$
RewriteRule ^(/)?$ /OPS/index.php [L]
Thank you all for your concern. As #anubhava mentioned the problem was with my document root. We revert back the htaccess to what ever it was. and overwrite the DOCUMENT_ROOT in top of the page and it is working:
if (strpos($_SERVER['DOCUMENT_ROOT'], '/var/www/websites/dev') !== false) {
// OPS(sub-folder)
$_SERVER['DOCUMENT_ROOT'] .= '/OPS';
}
I would like to over-write document root in htaccess if it would have been possible. any way this is the answer I came up with so far.
I want my domain without www always displayed, ie the URL is valid: http://miweb.net And besides this domain to point to a subdirectory and not the root directory.
How I can indicate in the htacess both conditions?
You may want to take a look at VirtualHost.
Assuming you are using Apache, this will allow you to redirect URLs with www or other sub-domains to different folders on the server.
I think I've found the solution. Apparently it works:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.)?myweb.net$
RewriteCond %{REQUEST_URI} !^/myweb/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /myweb/$1
RewriteCond %{HTTP_HOST} ^www\.myweb\.net$
RewriteRule ^/?$ "http\:\/\/myweb\.net\/" [R=301,L]
RewriteRule ^(/)?$ myweb/index.html [L]
If you access from a browser http://www.myweb.net, we automatically redirected to http://myweb.net (no www).
And that domain no longer points to the root directory of hosting "/ www /" if not "/ www / myweb /".
We just redesigned a site for a client in EE, located at example.com (with and without www.). Their original site is ASPX. They've still got a number of ASPX pages that they want to keep, so their IT people created a subdomain, www2, which is basically a clone of their old site.
I need an htaccess rule that will check if the requested page ends in .aspx, then redirects to the www2 subdomain. It should also make sure that the requested page doesn't exist
I tried using the following rule, but it doesn't work.
RewriteRule ^http://[www\.?]example.com/(.*)\.aspx$ http://www2.example.com/$1 [R=301,L]
My htaccess file (including the above rule) looks like this:
RewriteEngine On
# redirect all .aspx pages to www2
RewriteRule ^http://[www\.?]example.com/(.*)\.aspx$ http://www2.example.com/$1 [R=301,L]
# strip index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
Does anyone have a solution for this?
The RewriteRule directive does only test the URL path. If you want to test any other part of the requested URL, you need to use the RewriteCond directive:
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$
RewriteRule ^(.*)\.aspx$ http://www2.example.com/$1 [R=301,L]