Ubuntu 16.04 + Apache2 - .htaccess - .htaccess

I have small problem with Apache2 + Ubuntu 16.04, after install php, mysql ant other stuff, I can't go to subpage's by pretty URL.
All pages are in subfolder /var/www/html/:
sub1
sub2
sub3
URL: 192.168.1.23/sub1 - work
URL: 192.168.1.23/sub1/public/index.html - work
URL: 192.168.1.23/sub/c/product-name-123 - don't work, 404 error: The requested URL /index.php was not found on this server.
I made a lot of changes in 000-default.conf, apache2.conf but they dosen't work
My .htaccess
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [L]
php_flag log_errors on
php_value error_log ./logs/error.log

Related

Installing Codeigniter 4 in a subdirectory and keep the domain general URL structure

Current situation:
I already have a Wordpress installation at http://example.com and this site is multilanguage so you can access a web page in English at http://example.com/en/something-here/ and you can access the Spanish version of this webpage at http://example.com/es/algo-aqui/.
What I am trying to do:
I want to install Codeigniter 4 in http://example.com/software/ but I want to keep the general website URL structure, so I need to be able to access the CI4 software through the URL http://example.com/en/software/ and http://example.com/es/software/. Always reading the same CI4 installation mentioned at the beginning of this paragraph.
What I already tried:
I deployed the CI4 files at http://example.com/software/ and modified the .htaccess files of both, the Wordpress site and Code Igniter.
This is my WP .htaccess file on the root directory:
# Disable directory browsing
Options All -Indexes
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^[a-z]{2}/software(.*)$ /software/index.php$2 [L]
</IfModule>
# BEGIN WordPress
# Las directivas (líneas) entre `BEGIN WordPress` y `END WordPress` se generan dinámicamente
# , y solo se deberían modificar mediante filtros de WordPress.
# Cualquier cambio en las directivas que hay entre esos marcadores se sobreescribirán.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
And this is my .htaccess file on the "software" directory:
# Disable directory browsing
Options All -Indexes
# ----------------------------------------------------------------------
# Rewrite engine
# ----------------------------------------------------------------------
# Turning on the rewrite engine is necessary for the following rules and features.
# FollowSymLinks must be enabled for this to work.
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
# If you installed CodeIgniter in a subfolder, you will need to
# change the following line to match the subfolder you need.
# http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritebase
RewriteBase /
# Redirect Trailing Slashes...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Rewrite "www.example.com -> example.com"
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]
# Checks to see if the user is attempting to access a valid file,
# such as an image or css document, if this isn't true it sends the
# request to the front controller, index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) /software/index.php/$1
# Ensure Authorization header is passed along
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
ErrorDocument 404 index.php
</IfModule>
# Disable server signature start
ServerSignature Off
# Disable server signature end
The error I am getting:
I can access both, the site and the software. The site works well but when I try to access let's say http://example.com/en/software/, I get a 404 error when I access Codeigniter. The error message says: "Controller or its method is not found: App\Controllers\En::software".
This is as if CI is trying to find the controller En (that not exist) and the method software.
Any help will be appreciated.
I have solved the problem after trying for 2 days relentlessly. Here's the steps I actually followed-
First Backup the Codeigniter4 Application by giving the below command as root:
tar --exclude=".git" -czvf zipped_file_name.tar codeigniter4_project_folder/
upload the codeigniter4_project_folder in public_html directory at Shared Hosing and change the following:
Change the base url in app/Config/App.php or .env file in root folder of codeigniter application (here ci4 is the subdomain which will be configured in cpanel later)
app.baseURL = 'http://ci4.yourdomain.com/'
Change the Database Config in app/Config/Database.php or .env file in root folder
database.default.hostname = localhost
database.default.database = your_db_name
database.default.username = your_db_user
database.default.password = your_db_password
database.default.DBDriver = MySQLi
Change .htaccess file in Public Folder
RewriteBase /codeigniter4_project_folder/
Add the Subdomain in Cpanel ci4.yourdomain.com which path will be as follows:
public_html/codeigniter4_project_folder/public
Here public folder will be the last in the path. It is very important.
Hope this may help others struggling with the problem.
In my case I needed to add:
RewriteRule ^(.*)$ index.php?/$1 [L]
in public/.htaccess.

Error when proxying to blog sub domain from node.js application

I have a nodejs app hosted on heroku, on www.example.com
I then have a wordpress blog, currently on a subdomain - blog.example.com
I have a route setup in express:
(using express-http-proxy)
var proxy = require('express-http-proxy');
app.use('/blog', proxy('blog.example.com', {
forwardPath: function(req, res) {
return require('url').parse(req.url).path;
}
}));
This works, in the sense that I can see the blog "home page" on www.example.com/blog - it's proxying correctly and transparnelty to blog.example.com
However, if I visit any of the blog posts on there, it falls over with a 500 error
[error] [client (ipAddressHere)] Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace., referer: http://www.example.com/blog/
I suspect it’s something to do with my htaccess - but can’t quite figure out what?
My htaccess is:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>
# END WordPress
Removed /blog from my htaccess to make it:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
It now works
Transparent proxying from my node app /blog to wordpress blog!

Laravel 5 internal server error after moving to the server

My laravel 5 project is works well on localhost. After moving the project to the server it shows an internal server error.
Error message
The server encountered an internal error or misconfiguration and was unable to complete your request.
I checked the requirements. All requirements are correct.
PHP = 5.5
Mcrypt PHP Extension = Enabled
OpenSSL PHP Extension = Enabled
Mbstring PHP Extension = Enabled
Tokenizer PHP Extension = Enabled
Both .htaccess files on the root and public folder are same,
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
I tested by removing the both .htaccess files but it still shows the Internal server error.
How Can I fix this issue ? Any suggestions ?
check if mod_negotiation is enabled. I had the same issue just now
I have faced the same issue while migrating the shared server . The solution that worked me is as below.
Let's say there is laravel folder called test which contains folder structure of laravel.
I have use 2 different .htaccess file
1) one in the root folder of the (installed) laravel , i.e Along with test folder with content as below.
RewriteEngine On
RewriteCond %{REQUEST_URI} !^test/public
RewriteRule ^(.*)$ test/public/$1 [L]
2) One in the public folder i.e inside test/public with content as below.
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
It worked for me.

CakePHP 2.x .htaccess: Get 500 Internal Server Error

Problem solved
Changed all folder and file permissions to 755
All .htaccess files
with absolute paths (/app/webroot/)
I moved my CakePHP 2.x website to another hoster (cyon.ch). Now i got 500 Internal Server Error. I tryed all the fixed who are recommended for the 1and1 hoster, but they won't work.
The error comes from the /app/webroot/.htacces file, cause the others seems to work. If i try to call a image from the webroot/img directory, it works fine (www.myDomain.ch/img/myPicture.jpg), but not the index.php file.
AddType text/x-component .htc
<IfModule mod_rewrite.c>
RewriteEngine On
# FORCE WWW
RewriteCond %{HTTP_HOST} !^www\.myDomain\.ch$
RewriteRule ^(.*)$ http://www.myDomain.ch/$1 [R=301,L]
# REMOVE TRAILING SLASHES
RewriteRule ^(.*)/$ http://%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
The "FORCE WWW" and "REMOVE TRAILING SLASHED" are ok as well, if i type myDomain.ch/, i'll got redirect to www.myDomain.ch.
My Domain points to /path/to/root/public_html. Thats also the folder, in which the cake app folder is located.
Any idea?
Thanks in advance!
Edit: I found this error in the error log (Permissions for index.php are set to 755)
SoftException in Application.cpp:256: File "/home/myUsername/public_html/app/webroot/index.php" is writeable by group

CakePHP HTAccess 500 Internal Server Error, 404 Page Not Found errors

I'm using CakePHP 1.2 Version and When I upload my site on Live Server, it gives me 500 Internal Server Error
When I check mod_rewrite in phpinfo function, its not visible, but on same server another Joomla site is running perfectly fine without any problem of htaccess or path rewrite issue with AceSEF Component of Joomla for htaccess page / paths, so I believe as this is Shared server it must be that way.
I have tried different options like adding 'RewriteBase /' in root .htaccess file or trying the same in app/webroot/.htaccess files as well but no solution works for me.
Even when I write, 'RewriteBase /' in root .htaccess and app/.htaccess file, error changes to 400 Page Not Found. I don't know why.
Below is the .htaccess code:
root .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
app/.htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
app/webroot/.htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /index.php?url=$1 [QSA,L]
</IfModule>
I have read through some links like: Apache-and-mod_rewrite-and-htaccess though not much helpful
Any answer or solution for this error? Much appreciated !!
Thanks
Check if the rewrite module is linked in the enabled modules of apache. Like you said it isnt listed in phpinfo() so the module maybe isnt enabled and joomla has some workarounds.
(use following commands at your own risk, you need root access)
under debian/ubuntu; apache2 enable the module like that
cd /etc/apache2/mods-enabled/
ln -s ../mods-available/rewrite.load rewrite.load
you have to restart apache2
service apache2 restart
Then the module should be enabled! So try again.
Alternatively, tell the url you try to open!

Resources