How to remove index.php from subdomain nested folder - php

I have main domain http://example.com on my root directory and all of my subdomains are in catalogs folder /catalogs/subdomain1,/catalogs/subdomain2.Currently my subdomain url in http://subdomain.example.com/index.php
I want to remove index.php from my subdomain.
My Root .htaccess file code is
<IfModule mod_rewrite.c>
RewriteEngine On
# Redirect on https:
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
My Subdomain .htaccess
RewriteEngine on
# Redirect on https:
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
Options -Indexes
# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php56” package as the default “PHP” programming language.
<IfModule mime_module>
AddHandler application/x-httpd-ea-php56 .php .php5 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit

Please use below code and update RewriteBase /root_directory/subdomain_folder_name/ at your .htaccess file.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /root_directory/subdomain_folder_name/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
</IfModule>
I hope this will helpful for you.

Try this
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com$
RewriteRule (.*) http://subdomain.example.com/$1 [R=301,L]
RewriteRule ^$ folder [L]
DirectoryIndex index.php

Related

404 page not found while page redirection in codeigniter

Hi all I tried to redirect to dashboard controller addLocation function under admin folder i have given the link below its showing 404 page not found,
http://localhost/kooly/admin/dashboard/addLocation
This is my htaccess file help me to solve this redirection problem
.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /kooly/
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]
</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.
# Submitted by: ElliotHaughin
ErrorDocument 404 /index.php
</IfModule>
Try this and save outside of your application folder
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /your folder/
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond $1 !^(index\.php|assets|images|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</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>
Try the below .htaccess code.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php?/$0 [PT,L]
RewriteRule ^/?ajax/(.*)$ ajax.php?$1 [NC,QSA,L]
<IfModule mod_headers.c>
header add Access-Control-Allow-Origin: "*"
</IfModule>
You can add this code into your .htaccess file
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite all other URLs to index.php/URL
RewriteRule ^(.*)$ index.php?url=$1 [PT,L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 index.php
</IfModule>
It's working for me using codeigniter 3.
I hope it will work for you!!

HTTPS and Remove index.php on CodeIgniter

I am using codeigniter framework,set .htaccess file to remove index.php and trying to enable HTTPS protocol for the server, and something happened.
HTTP:
Everything is okay, when I access http://www.example.com/controller/method or http://www.example.com/index.php/controller/method
HTTPS:
Everything is okay, when I access https://www.example.com/index.php/controller/method
Got 404 not found when I access https://www.example.com/controller/method
I think that is .htaccess file problem, it is look like htaccess file not working for HTTPS protocol.
.htaccess file of my site.
DirectoryIndex index.php
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond $1 !^(index\.php|(.*)\.swf|forums|images|css|downloads|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php?$1 [L,QSA]
Is something wrong? thanks a lot.
Note: The SSL rewrite should happen before the index.php rewrite in your .htaccess file.
So, Don't do this setting (as we don't change anything in server apache config file.
)
AllowOverride All
just apply the Setting 2 it works.
I have faced the same issue and resolved it by adding
AllowOverride All
Setting 1:
FYI we have 2 config files.
Default Apache config (which runs with http)
SSL config (which runs with https)
Go to SSL config and add
<Directory "/var/www/html">
AllowOverride All
</Directory>
**Setting 2:**The .htaccess file should be like this...
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L]
</IfModule>
It worked for me.
First you remove $config['base_url] from your config file and put ''(blank) in your $config['index'] attribute ..
please set your .htaccess file like..
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite all other URLs to index.php/URL
RewriteRule ^(.*)$ index.php?url=$1 [PT,L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 index.php
</IfModule>
Try this
I used this in one of my project. May its helps you
#AuthType Basic
#AuthName "restricted area"
#AuthUserFile /home/site_name/public_html/.htpasswd
#require valid-user
RewriteEngine On
#RewriteBase /
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.site_name.com/$1 [R,L]
RewriteCond %{HTTP_HOST} ^([a-z.]+)?.site_name.lk$ [NC]
RewriteRule ^(.*)$ https://www.site_name.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^([a-z.]+)?site_name\.com$ [NC]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .? https://www.%1site_name.com%{REQUEST_URI} [R=301,L]
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# RewriteCond $1 !^(index\.php|assets|files|robots\.txt)
# RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
</IfModule>
Note site_name in the above htaccess should replaced to your website name
you can try this, it works for my project.
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
RewriteCond $1 !^(index\.php|(.*)\.swf|forums|images|css|downloads|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
reference: https://wiki.apache.org/httpd/RewriteHTTPToHTTPS
if you want to http->https AND remove www AND remove index.php here's the solution:
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,NE,R=301]
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L]
</IfModule>

CodeIgniter mod_rewrite with apache 2.4

I'm having trouble getting mod_rewrite to work with CodeIgniter. I'm running apache 2.4.
My web root is /Users/Jason/Development/www
This is the code I currently have in my .htaccess file located in the same directory as my main index.php file.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /myapp/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
What am I doing wrong? I keep getting a 404 page saying the requested URL was not found on this server.
Options -Indexes +FollowSymLinks
RewriteEngine On
RewriteBase /
# exclude any paths that are not codeigniter-app related
RewriteCond %{REQUEST_URI} !^/server-status
RewriteCond %{REQUEST_URI} !^/server-info
RewriteCond %{REQUEST_URI} !^/docs
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
<IfModule mod_php5.c>
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
# the following is for rewritting under FastCGI
<IfModule !mod_php5.c>
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
Base on sigmoid https://www.npcglib.org/~stathis/blog/2013/08/12/apache-tip-rewriting-urls-with-apache-2-4-php-fpm-mod_fastcgi_handler-codeigniter/

Symfony 2 Redirect to url without www

I don't know how to redirect my symfony application from:
http://www.mysymfonyapp.com
to:
http://mysymfonyapp.com
Here is my .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [R=301,L]
#<IfModule mod_vhost_alias.c>
# RewriteBase /
#</IfModule>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteBase /mysymfonyapp.com/web/
RewriteRule ^(.*)$ index.php [QSA,L]
If I'm entering application without 'www' it works, but with 'www' it has redirects loop. I've tried asking google, but I didn't find anything.
Ok, I figured it out and answering for others.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.mysymfonyapp\.com$ [NC]
RewriteRule (.*) http://mysymfonyapp.com/$1 [R=301,L]
#<IfModule mod_vhost_alias.c>
# RewriteBase /
#</IfModule>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteBase /mysymfonyapp.com/web/
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.mysymfonyapp\.com$ [NC]
RewriteRule (.*) http://mysymfonyapp.com/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
#RewriteBase /mysymfonyapp.com/web/ (you don't need declare RewriteBase if you have this code in mysymfonyapp/web/.htaccess)
RewriteRule ^(.*)$ app.php [QSA,L] #Remember to redirect app.php
</IfModule>

VHost & htaccess - 500 Internal Server error

I use ISPConfig 3 to manage my domains/subdomains.
I added subdomain parim.kristian.ee which would redirect to web/parim/ (note: web/ is my document root).
ISPConfig generated such redirect to apache config:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^parim.kristian.ee [NC]
RewriteRule ^/(.*)$ /parim/$1 [L]
Now if i'll try to get static resources, such as http://parim.kristian.ee/images/1x1.gif, it serves fine, but when redirect is to codeigniter, it doesn't work.
Htaccess in web/parim/ looks like this:
<IfModule mod_rewrite.c>
RewriteEngine on
Options -Indexes
#Handle CodeIgniter request
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 ./index.php
</IfModule>
NOTE: accessing the same folder via http://kristian.ee/parim/ works!
I s*ck at htaccess, so any help is appreciated.
# To remove index.php from URL
RewriteEngine On
RewriteBase /parim
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
Or Simple remove RewriteBase /parim

Categories