I am attempting to migrate a portal (including login ability) over to a new website. The new site is designed in Wordpress and all of the expression engine files are tossed into a subdirectory outside of the wordpress install.
The entire old site (which was working and all built on Expression Engine) and copy it into the sub-directory (lets call it "old".
Then I went to the .htaccess file and
Updated /old/.htaccess with the following:
RewriteBase /old/
(it was originally RewriteBase / )
It shows that it goes to the directory but it shows my index wordpress page (that is index.php BUT it is just my home page of the wordpress install and not the log in page that I expect).
This is my .htaccess file code (inside of the "old" directory which is a subdirectory of the root directory:
RewriteEngine On
RewriteBase /assets/
# Removes index.php from ExpressionEngine URLs
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteCond %{REQUEST_URI} !/asysteme/.* [NC]
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]
# Directs all EE web requests through the site index file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
BUt all it does is take the page to the index page of the root.
Check your WordPress .htaccess isn't taking control because it has to pass through that htaccess file before it gets to the subfolder htaccess file (EE). So ensure this line is in the WordPress htaccess:
RewriteCond %{REQUEST_FILENAME} !-d
Which excludes physical directories on the server from being rewritten and will let requests through to the EE folder and therefore the EE htaccess.
Your ExpressionEngine htaccess file has:
RewriteBase /assets/
Shouldn't this be:
RewriteBase /old/
Try the following:
RewriteEngine On
# Removes index.php from ExpressionEngine URLs
# RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
# RewriteCond %{REQUEST_URI} !/asysteme/.* [NC]
# RewriteRule (.*?)old/index\.php/*(.*) /$1$2 [R=301,NE,L]
# Directs all EE web requests through the site index file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /old/index.php/$1 [L]
To isolate the problem/solution, comment out the removal of the index.php from the URL (this is if someone has specifically entered index.php in the URL). Once the site is working, add this back in.
Remove the rewrite base to simplify things and add the sub-folder into the rewrite rule. This should then resolve the issue.
Related
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 have a setup where I have a couple of sites hosted in different subfolders in the root of my FTP
ROOT
-site1folder
-site2folder
I have 2 domain names not associated with the account. I have changed the DNS records of the domains to point to my hosting account but I need the 2 different URLs to go to the correct subfolder to load the correct site rather than transfer the domains. The domains are
www.site1.com
www.site2.com
Ideally I would like site1 to load the contents of the site1folder and the same for site 2 and its corresponding folder.
I currently have a .htaccess file in my root which I have mashed together from looking at different posts. I am a newbie to .htaccess. I am currently trying to get site 1 to point to the site1 folder
Options +FollowSymLinks
#Turns the rewrite engine on.
RewriteEngine on
#Fix missing trailing slash character on folders.
RewriteRule ^([^.?]+[^.?/])$ $1/ [R,L]
RewriteBase /website1
#www.site1.co.uk and site1.co.uk will map to the folder
RewriteCond %{HTTP:Host} ^(?:www\.)?site1\.co.uk
RewriteRule (.*) /site1 [NC,L,NS]
What happens when I load this is I get the contents of the site1 folder but at this URL site1.co.uk/site1
I don't want the URL to change at all. I just want it to load the contents of the subfolder it is pointed to.
Ok people I managed to solve this one myself in the end after lots of head banging and reading a lot of the docs to decyfer others code. Here is what I did...
Options +FollowSymLinks
RewriteEngine on
#========================================================================
# FIRST Handle the http requests first before removing the additional url junk
#========================================================================
#rule for site1.com to link to site1folder directory
RewriteCond %{HTTP_HOST} ^(www.)?site1.com$
RewriteCond %{REQUEST_URI} !^/site1folder/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /site1folder/$1
#rule for site2.com to link to site2folder directory. Its the same as above just with site2 URL and subfolder
RewriteCond %{HTTP_HOST} ^(www.)?site2.com$
RewriteCond %{REQUEST_URI} !^/site2folder/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /site2folder/$1
#==========================================================
# SECOND Remove the additional url junk once the new url is loaded
#==========================================================
#rule for site1 url rewrite to remove /site1foler/index.php from the URL
RewriteCond %{HTTP_HOST} ^(www.)?site1.com$
RewriteRule ^(/)?$ site1folder/index.php
#rule for site2 url rewrite to remove /site2foler/index.php from the URL. Again its the same as above just with the site2 URL and sub folder info.
RewriteCond %{HTTP_HOST} ^(www.)?site2.com$
RewriteRule ^(/)?$ site2folder/index.php
Hopefully you can see where the repetition is in this so if you wished to add more sites down the line to it you could by copying and pasting the data and changing the site URL and sub folder to match the additional ones you wish to add.
I hope this has managed to help some of you. Also if you can see issues with this then it would be very much appreciated as I am a newbie at .htaccess files and as you can imagine, I figured as it works, it must be right.
I have used this in a Dedicated Windows Server using xampp. It works fine to me with SSL
# mydoamin.com starts ############################
RewriteCond %{HTTP_HOST} ^(www.)?mydoamin.com$
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
# mydoamin.com ends ############################
# mydoamin.in starts ############################
#RewriteCond %{HTTP_HOST} ^(www.)?mydoamin.in$
#RewriteCond %{HTTPS} !on
#RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
# mydoamin.in ends ############################
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.
Well I have a main website which runs ELGG1.8 and it needs it's own created htaccess to function properly. But now I want to create a subdirectory in my main folder and the main /htaccess is messing it up, I cannot acces the folder, just run html files, no php, nothing..
How can I edit this .htaccess to make an exception?
<IfModule mod_rewrite.c>
RewriteEngine on
# If Elgg is in a subdirectory on your site, you might need to add a RewriteBase line
# containing the path from your site root to elgg's root. e.g. If your site is
# http://example.com/ and Elgg is in http://example.com/sites/elgg/, you might need
#
#RewriteBase /sites/elgg/
#
# here, only without the # in front.
#
# If you're not running Elgg in a subdirectory on your site, but still getting lots
# of 404 errors beyond the front page, you could instead try:
#
#RewriteBase /
# In for backwards compatibility
RewriteRule ^pg\/([A-Za-z0-9\_\-]+)$ engine/handlers/page_handler.php?handler=$1&%{QUERY_STRING}
RewriteRule ^pg\/([A-Za-z0-9\_\-]+)\/(.*)$ engine/handlers/page_handler.php?handler=$1&page=$2&%{QUERY_STRING}
RewriteRule ^tag\/(.+)\/?$ engine/handlers/page_handler.php?handler=search&page=$1
RewriteRule ^action\/([A-Za-z0-9\_\-\/]+)$ engine/handlers/action_handler.php?action=$1&%{QUERY_STRING}
RewriteRule ^cache\/(.*)$ engine/handlers/cache_handler.php?request=$1&%{QUERY_STRING}
RewriteRule ^services\/api\/([A-Za-z0-9\_\-]+)\/(.*)$ engine/handlers/service_handler.php?handler=$1&request=$2&%{QUERY_STRING}
RewriteRule ^export\/([A-Za-z]+)\/([0-9]+)\/?$ engine/handlers/export_handler.php?view=$1&guid=$2
RewriteRule ^export\/([A-Za-z]+)\/([0-9]+)\/([A-Za-z]+)\/([A-Za-z0-9\_]+)\/$ engine/handlers/export_handler.php?view=$1&guid=$2&type=$3&idname=$4
RewriteRule xml-rpc.php engine/handlers/xml-rpc_handler.php
RewriteRule mt/mt-xmlrpc.cgi engine/handlers/xml-rpc_handler.php
# rule for rewrite module test during install - can be removed after installation
RewriteRule ^rewrite.php$ install.php
# Everything else that isn't a file gets routed through the page handler
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([A-Za-z0-9\_\-]+)$ engine/handlers/page_handler.php?handler=$1 [QSA]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([A-Za-z0-9\_\-]+)\/(.*)$ engine/handlers/page_handler.php?handler=$1&page=$2 [QSA]
</IfModule>
Right underneath the RewriteEngine on, in your htaccess file, add this rule to allow requests for the directory to pass-through:
RewriteRule ^directory/to/pass/through - [L]
This makes it so when someone requests http://your.domain.com/directory/to/pass/through, the rewrite engine will let that through without interferring with it.
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]