Removing index.php from subdomain codeigniter 3 - codeigniter

I have looked on a few Stack Overflow questions for removing index.php from sub domain url please don't mark as duplicate.
Stack Overflow I have Read And Tried.
CodeIgniter in subdomain folder, removing the index.php from address
remove index.php of codeigniter subdomains
Removing index.php and handling subdomains of two Codeigniter sites, when one within the other
But non seem to work I am using WAMP and Codeigniter 3 and have MOD Rewrite enabled. Also I use virtual host.
Question: What is the best suitable htacces for sub domain so that I can have the index.php remove?
Page Error:
codeigniter 500 internal server error
My Folder Structure is
www /
www / codeigniter / cms-1 <-- This is main project
www / codeigniter / cms-1 / application
www / codeigniter / cms-1 / cms-2 <-- This is sub domain
www / codeigniter / cms-1 / cms-2 / index.php
www / codeigniter / cms-1 / cms-2 / .htaccess
www / codeigniter / cms-1 / image /
www / codeigniter / cms-1 / system
www / codeigniter / cms-1 / .htaccess
www / codeigniter / cms-1 / index.php
When I have URL on WAMP like below does not work.
http://www.cms-2.cms-1.com/information/information/3
But when I have index.php works.
http://www.cms-2.cms-1.com/index.php/information/information/3
I have removed on the application > config > config.php
$config['index_page'] = '';
This .htaccess below is on Main directory and works fine for main
domain.
Options +FollowSymLinks
# Prevent Directoy listing
Options -Indexes
# Prevent Direct Access to files
<FilesMatch "(?i)((\.tpl|\.ini|\.log|(?<!robots)\.txt))">
Order deny,allow
Deny from all
</FilesMatch>
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [L,QSA]

Use this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>

Replace your base_url
if(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on"){$ssl_set = "s";} else{$ssl_set = "";}
$config['base_url'] = 'http'.$ssl_set.'://'.$_SERVER['HTTP_HOST'];
In .htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
For more read this http://w3code.in/2015/10/how-to-make-multiple-websitesubdomain-of-your-main-site-in-codeigniter-with-same-code-and-database-dynamically/

Related

Laravel 5.8 showing 404 Not Found errors

I change the index.php file path public to root. After adding a .htaccess file in the root path (laravel 5.7) every page working fine. But in laravel 5.8 when I click another page, it's showing 404 Not Found.
My .htaccess file is below.
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
#Send request via index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d``
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
The content of a Laravel .htaccess file should look like this:
<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 webroot has to be set to the /public directory. Don't try to search for other solutions that move the index.php and .htaccess file from /public to the root directory of your Laravel application. There is absolutely no reason why you want to move the webroot from /public to /. index.php sits in /public for a reason. If your webhost does not offer the ability to move the web root to another directory switch your hoster.
It might be that you have created your folder as Example and trying to access it via example
ie
localhost/Example/public
yet accessing it like
localhost/example/public

Handling codeigniter application on server

I have CODEIGNITER site live and running successfully on a server, but when I move(copy and paste) the contents in another folder on the same server I am getting 404 page not found error.
Any ideas why?
Use this htaccess in the project folder not in application folder
<IfModule mod_rewrite.c>
RewriteEngine On
# !IMPORTANT! Set your RewriteBase here and don't forget trailing and leading
# slashes.
# If your page resides at
# http://www.example.com/mypage/test1
# then use
# RewriteBase /mypage/test1/
RewriteBase /
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.
# Submitted by: ElliotHaughin
ErrorDocument 404 /index.php
</IfModule>
If your folder is not follow like that public_html/project_folder
than change here
RewriteBase project_folder/

Why can I not remove index.php from codeigniter URL

I have a new installation of Kubuntu 15.10 with old (working) code from my site.
Somehow I can not get rid of the index.php in the URL.
I tired dozens of suggestions but nothing seems to work.
My current status is this:
Apache 2 have mod_rewrite on:
printout of php_info()
Apache2 config is:
<Directory /var/www>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
My .htaccess is located under application folder:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
# Hide the application and system directories by redirecting the request to index.php
RewriteRule ^(application|system|\.svn) index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [QSA,L]
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
# Without mod_rewrite, route 404's to the front controller
ErrorDocument 404 /index.php
</IfModule>
What am I missing here? I am loosing faith... :-P
Step 1: In your .htaccess replace all other codes..try with this:
RewriteEngine On
RewriteRule ^(application) - [F,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
Step 2: Move your .htaccess from application folder to where index.php located.
Step 3: Change in your config.php
From:
$config['index_page'] = 'index.php';
to
$config['index_page'] = '';
Try it in application/.htaccess, index.php will exists in url but in scripts it will be ignored.
# Turn on URL rewriting
RewriteEngine On
# Installation directory
RewriteBase /
# Protect hidden files from being viewed
<Files .*>
Order Deny,Allow
Deny From All
</Files>
# Protect application and system files from being viewed
RewriteRule ^(?:application|modules|system)\b.* index.php/$0 [L]
# Allow any files or directories that exist to be displayed directly
RewriteCond ${REQUEST_URI} ^.+$
RewriteCond %{REQUEST_FILENAME} \.(gif|jpe?g|png|js|css|swf|php|ico|txt|pdf|xml)$ [OR]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -l
RewriteRule ^ - [L]
# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php/$0 [PT]

Laravel sets wrong public path with a index.php file is requested in a subdirectory

In Laravel 4.2 using Apache 2.4, if I access an index.php different from index.php in the site root then the public path is set wrong. For instance, the html document returned by /site/index.php is right, but all its routes to assets are relative to /site. For instance,
File system path: /var/www/htdocs/imgs/logo.png
Right url: /imgs/logo.png
Real path: /site/imgs/logo.png
This issue was discovered because the old site had you index file in /site/index.php and was indexed by the search engines. Then when the site is shown in the search results, it shows a link to site/index.php with all the assets paths broken.
The paths to assets are set with Laravel's function as HTML::style or assets
How do I redirect all the index.php files inside a subpath to index.php in the root file, except this last?
The default .htaccess of Laravel 4.2 is
<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>
Then I add a new Rewrite Rule before #Handle Front Controller
# Redirect to index.php if other index.php distict to the index.php is requested.
RewriteCond %{REQUEST_URI} ((.+)/)+index.php [NC]
RewriteRule ^ / [R=301]
So, I redirect (permanently) to the site root to any index.php in a subdirectory.

How to allow WordPress and Laravel to share top level URLs with htaccess

Edit: This is a major edit of my question, based on feedback in the comments, and a bit of reading on meta.stackoverflow.
I've shifted my goals, now my priority is to route top level URLs between Laravel and WP: I no longer seek to share code / databases / user creds, etc.
Question: What rewrite rules do I need to achieve a URL structure like this:
/ // (home) delivered by WP
/content1 // WP
/content(n) // WP
/dashboard // delivered by Laravel
/widgets/mywidget/ // Laravel
all Laravel pages will be in /admin or /widgets, everything else will be handled by WordPress, including 404s
I will keep WP and Laravel completely separate.
My colleague and I will edit WP using Admin accounts, there will be no other WP users
I will manage presentation for the two apps completely separately
I've setup my files as follows, and have tested that each application works independently of one another. (Ie if Laravel's rewrite rules are the only ones in use, Laravel works fine using laravel-index.php)
From the web root: public_html/
/wordpress
/laravel3 // app dir
/css // these are from the laravel public dir
/images //
/js, etc //
/index.php // WP index.php
/laravel-index.php // laravel's index.php
I'm in a shared hosting environment with no access to httpd.conf.
Here is my .htaccess
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^widgets - [L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
# Laravel
<IfModule mod_rewrite.c>
RewriteRule !^widgets - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ laravel-index.php/$1 [L]
</IfModule>
In this way:
I can reach my WordPress pages, and
WP serves a WP-404 for unknown URLs, but
/widgets gets a vanilla server 404, whilst
/laravel-index.php/widgets displays the proper content.
An additional problem is that WP Dashboard is stealing requests to /dashboard, which I'd like to redirect to Laravel
Thanks for reading!
For WordPress, you need to send all requests that are not in the widgets or dashboard folders to index.php
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond !^widgets
RewriteCond !^dashboard
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
For Laravel, you need to do the opposite, send ONLY requests that are inside widgets or dashboard to laravel-index.php
# Laravel
<IfModule mod_rewrite.c>
RewriteCond ^widgets
RewriteCond ^dashboard
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ laravel-index.php/$1 [L]
</IfModule>

Resources