htaccess problem in https url codeigniter - codeigniter

I am having problem in my htaccess file. Would someone help me to identify the problem.
I actually removed the index.php in
foldername/application/config/config.php
I added this in vhost of my apache and restarted services
<VirtualHost *:80>
ServerAdmin user#mai.com
DocumentRoot "C:/server/Apache24/htdocs/foldername"
<Directory "C:/server/Apache24/htdocs/foldername">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ServerName https://foldername.com
ServerAlias https://foldername.com
ErrorLog "logs/dummy-host.example.com-error.log"
CustomLog "logs/dummy-host.example.com-access.log" common
</VirtualHost>
This works actually on my localhost, but when I configure the url, I added https because I need it to be in https, the htaccess doesn't work.
Here's my htaccess:
RewriteEngine On
RewriteRule ^(application) - [F,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
<Limit GET POST>
order deny,allow
deny from all
allow from all
</Limit>
<Limit PUT DELETE>
order deny,allow
deny from all
</Limit>
Thank you in advance.

Related

How to redirect calls from my-domain/api/specific-route to my-domain/api/api/specific-route?

I have a site being served by an Apache server, with the following structure:
On the main directory, I have a front-end app.
On a subdirectory named API, I have an API running on Laravel.
When I make calls to the API the URL look like this: domain/api/api/specific-route
I would like it to look like this: domain/api/specific-route
This is the relevant part of the virtual host config file:
ServerName my-domain.com
ServerAlias www.my-domain.com
ServerAdmin webmaster#localhost
DocumentRoot /var/www/my-domain
<Directory /var/www/my-domain>
RewriteEngine On
RewriteBase /
# Serve files when they are found
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
RewriteRule ^ - [L]
# When file is not found, serve index.html instead
RewriteRule ^ /index.html
</Directory>
<Directory /var/www/my-domain/api>
RewriteEngine on
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
Require all granted
</Directory>
ErrorLog /var/www/my-domain/error.log
CustomLog /var/www/my-domain/access.log combined
# Aliases
Alias /api /var/www/my-domain/api/public

i get access forbidden from Apache (httpd) in fedora 34, Laravel, SELinux

I have configured httpd in my fedora and I checked everything is true but i get
access forbidden
I have tested everything about .htaccess but still getting access forbidden. also, my laravel folder permissions are correct.
I tested a sample project while installing httpd it worked perfectly with no 'access forbidden' message.
this is my httpd config
<VirtualHost *:80>
ServerName test.com
ServerAlias www.test.com
DocumentRoot /home/myuser/gitlab/register/public
<Directory /home/myuser/gitlab/register/public>
DirectoryIndex index.php
AllowOverride All
Require all granted
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
this is my htaccess in laravel public folder
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
your probably creating the issue by mixing old Apache syntax with new Apache syntax, modern versions of Apache should be something like this...
<VirtualHost *:80>
ServerName test.com
ServerAlias www.test.com
DocumentRoot /home/myuser/gitlab/register/public
<Directory /home/myuser/gitlab/register/public>
DirectoryIndex index.php
AllowOverride All
Require all granted
# Order allow,deny
# Allow from all
</Directory>
</VirtualHost>
I found the problem.
it is because of the
SELinux
ubuntu does not uses SELinux by default but RedHat distributions use it by default. SELinux prevents apache to access the home directory for the sake of security so if you disable or put it to Permissive mode, apache can access your home directory to load the web project. if you do not want to disable SELinux so the correct location for web applications is in /var/www/ folder
so if we change httpd config to
<VirtualHost *:80>
ServerName test.com
ServerAlias www.test.com
DocumentRoot /var/www/gitlab/register/public
<Directory /var/www/gitlab/register/public>
DirectoryIndex index.php
AllowOverride All
Require all granted
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
it works fine

wildcard sub-domain on localhost using codeigniter

I have setup virtual host on my localhost by using codeigniter and it is working fine. But I am not able to create wildcard subdomains. To add virtual host below are my steps on windows machine.
C:\Windows\System32\drivers\etc\hosts.txt
In this host.txt I have added below line
127.0.0.1 localhost.com
I am using xampp .I have added below lines in httpd-vhosts.conf file.
D:\xampp\apache\conf\extra\httpd-vhosts.conf
<VirtualHost localhost.com:80>
DocumentRoot "D:/xampp/htdocs/adeptra"
ServerName localhost.com
ServerAlias localhost.com
<Directory "D:/xampp/htdocs/adeptra">
Options Indexes FollowSymLinks
AllowOverride All
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "D:/xampp/htdocs/adeptra"
ServerName localhost.com
ServerAlias *.localhost.com
<Directory "D:/xampp/htdocs/adeptra">
Options Indexes FollowSymLinks
AllowOverride All
</Directory>
</VirtualHost>
Below is my .htaccess code to remove index.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
So now my question is, is it really possible to create wildcard subdomains in localhost? If yes, then please help me in this regard. Any help would be greatly appreciated.
A similar question has already been asked and answered here. Basically, no you cannot create subdomains on localhost. You need to create a local domain which is explained in the linked answer.

Getting forbidden 403 error only on https but url http working fine

on my server I have wordpress site on root and codeigniter project as sub folder in wordpress and I made subdomain for codeigniter project. Both are working fine without SSL Now I want to apply SSL on subdomain project while applying ssl on this I am facing issue. When I am opening site by using https://subdomain.example.com it is giving me forbidden 403 error.
Following is the example of my sites hosted on apache. I had symbolic link for my root wordpress project.
http://example.com - working fine - wordpress project on root
http://subdomain.example.com - working fine - codeigniter project under wordpress project folder
https://subdomain.example.com - getting forbidden error
Following is my apache ssl virtual host file data.
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerAlias subdomain.example.com
ServerName subdomain.example.com
DocumentRoot /var/www/html/wordpress
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLEngine on
SSLCertificateFile /home/ubuntu/wordpress/cdq/my-ssl-certifications/fc1d71b08ac8aab1.crt
SSLCertificateKeyFile /home/ubuntu/wordpress/cdq/my-ssl-certifications/host.key
SSLCertificateChainFile /home/ubuntu/wordpress/cdq/my-ssl-certifications/gd_bundle-g2-g1.crt
<FilesMatch "\.(cgi|shtml|phtml|php)$">
SSLOptions +StdEnvVars
</FilesMatch>
<Directory /usr/lib/cgi-bin>
SSLOptions +StdEnvVars
</Directory>
<Directory /var/www/html/wordpress>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
</IfModule>
htaccess of wordpress project
RewriteEngine On
RewriteCond %{HTTP_HOST} subdomain.example.com$
RewriteCond %{REQUEST_URI} !^/subfolder
RewriteRule ^(.*)$ /subfolder/$1 [L]
RewriteBase /
RewriteRule ^index\.php$ - [L]
# add a trailing slash to /wp-admin
RewriteRule ^wp-admin$ wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^(wp-(content|admin|includes).*) $1 [L]
RewriteRule ^(.*\.php)$ $1 [L]
RewriteRule . index.php [L]
htaccess of subfolder project
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^(.*)$ /index.php/$1 [L]
There is some permission related issue in your configuration :
<Directory /var/www/html/wordpress>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
it require granted for all files. So all you have to do is make it like :
<Directory "/var/www/html/wordpress">
AllowOverride All
</Directory>
P.S. I have modified your file and you use it like :
<IfModule mod_ssl.c>
<VirtualHost _default_:443>
ServerAlias subdomain.example.com
ServerName subdomain.example.com
DocumentRoot /var/www/html/wordpress
<Directory "/var/www/html/wordpress">
AllowOverride All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLEngine on
SSLCertificateFile /home/ubuntu/wordpress/cdq/my-ssl-certifications/fc1d71b08ac8aab1.crt
SSLCertificateKeyFile /home/ubuntu/wordpress/cdq/my-ssl-certifications/host.key
SSLCertificateChainFile /home/ubuntu/wordpress/cdq/my-ssl-certifications/gd_bundle-g2-g1.crt
<FilesMatch "\.(cgi|shtml|phtml|php)$">
SSLOptions +StdEnvVars
</FilesMatch>
<Directory /usr/lib/cgi-bin>
SSLOptions +StdEnvVars
</Directory>
BrowserMatch "MSIE [2-6]" \
nokeepalive ssl-unclean-shutdown \
downgrade-1.0 force-response-1.0
BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown
</VirtualHost>
There is no major change. I just modify it according to my working file. Hope it helps you.
Finally resolved the issue. Issue was with the permissions of project folder structure. Now everything is working fine

Redirect home URL to Magento folder

I have Magento installed on my site at mydomain.com/magento. I'm happy with it to stay in this directory, however when people visit the site directly (i.e. mydomain.com) I would like this to open the Magento folder. How can I do this?
Thank you very much.
You have to make your server redirect "mydomain.com" to the directory you have installed Magento at. If you are using apache you could add a virtualhost like the one below to your httpd.conf:
<VirtualHost *:80>
ServerName mydomain.com
DocumentRoot "/yourpath/magento"
CustomLog "/tmp/access_log" common
LogLevel debug
ErrorLog "/tmp/error.log"
<Directory "/yourpath/magento">
Options FollowSymLinks Multiviews Indexes
MultiviewsMatch Any
# Rewrites to allow links
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# We are not allowing any directive contained in a .htaccess file
AllowOverride None
# We grant all permissions
Require all granted
</Directory>

Resources