I have pages inside a folder named frontend/page and url shows like www.domain.com/frontend/page/home.
How do I change it to www.domain.com/home
Also the entry home is dynamic it could be about us or contact
My .htaccess file is
# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php56” package as the default “PHP” programming language.
<IfModule mime_module>
AddType application/x-httpd-ea-php56 .php .php5 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit
RewriteEngine on
RewriteCond $1 !^(index\.php|assets|uploads|documentation|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
If you want to redirect any page to it's corresponding controller which is in frontend/page sub-directory, you could modify the routes like below :
$route['(:any)'] = "frontend/page/$1";
Related
When i deployed my laravel application to public_html/demo folder. Its working well in this folder but when i moved all my codes to public_html/ folder am getting a blank page, Also am not getting any errors in log/laravel.log, What should i do and why this problem is occurring
After so much of research i found the problem.
The PHP was not loading.
By adding these lines in the .htaccess file it resolves my problem
DirectoryIndex index.php login.php index.html
RewriteEngine on
# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php70” package as the default “PHP” programming language.
<IfModule mime_module>
AddType application/x-httpd-ea-php70 .php .php7 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit
add .htaccess file in your public html and write this
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ demo/public/$1 [L]
</IfModule>
you should change the root folder using .htaccess like that
I am using CodeIgniter for my web app and i want to avoid on keep using base_url() function in all my urls in the views.
Now this code is what i want :
Click me to create user
instead of
Click me to create user
However, specifying "/user/create" will redirect me to below url which is incorrect
http://localhost/user/create
What i want is that "/user/create" url in href should automatically redirect me to
http://localhost/myapp/user/create
without specifying base_url()
Is this possible?
This is my current .htaccess file
<IfModule mod_rewrite.c>
# Turn on URL rewriting
RewriteEngine On
# If your website begins from a folder e.g localhost/my_project then
# you have to change it to: RewriteBase /my_project/
# If your site begins from the root e.g. example.local/ then
# let it as it is
RewriteBase /myapp/
# Protect application and system files from being viewed when the index.php is missing
RewriteCond $1 ^(application|system|private|logs)
# Rewrite to index.php/access_denied/URL
RewriteRule ^(.*)$ index.php/access_denied/$1 [PT,L]
# Allow these directories and files to be displayed directly:
RewriteCond $1 ^(index\.php|robots\.txt|favicon\.ico|public|assets|css|js|images)
# No rewriting
RewriteRule ^(.*)$ - [PT,L]
# Rewrite to index.php/URL
RewriteRule ^(.*)$ index.php/$1 [PT,L]
</IfModule>
Any help would greatly be appreciated.
Thanks
you can use form helper library
//Controller
function __construct()
{
parent:: __construct();
$this->load->helper('url');
$this->load->helper('form');
}
//View
<?php echo anchor('user/create','Click me to create user');?>
This will create similar result as
Click me to create user
They are way much better than using base_url() for links.
Try this:
href="user/create"
Just remove the first slash (/) before user and try.
I have my codeigniter code in web root. The mod_rewrite is enabled.. I checked through phpinfo.php. Now the code structure is something like this
controllers/home.php(default controller)
controllers/products.php (not listed in routes.php under config)
and then a subfolder
controllers/members/login.php
The urls I am trying are
domain_name/ ---------> works
(Note: this is where my echo base_url is pointing me to I guess
because $config['index.php'] = '', But even setting it to index.php is
not pointing me to the working index.php url)
domain_name/products ------> doesn't work
domain_name/index.php/products ------> works
similarly
domain_name/members ----->doesn't work
domain_name/index.php/members --->work
Because this thing is working with index.php I am guessing the routes.php is working fine. But some how echo $base_url is pointing me to these without index.php urls.
I have tried the .htacess file which is in my webroot that is /var/www/
The version for codeigniter is 2.1.3
Please help. I want this to work with or without index.php and if you can explain what i am missing please give me explaination.
In General Codeigniter tends to explicity hide index.php when call the its main root but when your trying to access its subfolders directly in the url .. index.php is required.In order to do that so you must include an .htaccess inside your ci filesystem that will accept the use of domain/product or domain/index.php/product
So try to include this .htacess and change its rewrite base into your ci folder name
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /cifolder
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [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 index.php
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>
I have urls that all contain /main/ in the url as it is my main controller.
I'd like to get rid of it.
I understood in the User Guide that the routing class will only re-route my URL, not hide a part of it (it is segment 1 according to their docuementation).
Thus, I've found this:
$route['(:any)'] = "auth/$1";
But I have 404 errors (That's the only modification I made to routing.php)
I believe I'll have to do it in the .htaccess, but I don't know what should be the syntaxe for that. For now, my .htaccess is this one:
<IfModule mod_rewrite.c>
SetEnv MAGIC_QUOTES 0
SetEnv PHP_VER 5
# For security reasons, Option followsymlinks cannot be overridden.
# Options +FollowSymlinks -MultiViews
Options +SymLinksIfOwnerMatch -MultiViews
RewriteEngine On
DirectoryIndex index.php
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [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 index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|images|robots\.txt|css)
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>
I am using several controllers and my links are similar to this one :
Thanks
Try this:
$route['blog'] = 'blog'; // seem stupid but otherwise the (:any) route below will send it to main
$route['blog/(:any)'] = 'blog/$1'; // to have blog cotroller work
$route['blog/(:any)/(:any)'] = 'blog/$1/$2';
// repeat for other controllers
$route['(:any)'] = "main/$1";
$route['(:any)/(:any)'] = "main/$1/$2"; // if you use other uri parameter
$route['default_controller'] = 'main'; // to have your main page work...
And put before this directive all calls to other controller as this will prevent all other controller calls.
I have a multi city application and have the following setup for my application
This is outside the server root
framework
backend
frontend
CI_2.0.1
system
Now in server root i have 2 folders to represent 2 cities
html
city1
city1.php
city2
city2.php
I need to add a rule to get rid of the .php in the url so it looks more like
http://example.in/city1/search
http://example.in/city2/search
Or a rule to completely get rid of the index.php file
To index.php and some more .htaccess trick I use this code (CI 2):
# Deny OR Allow Folder Indexes.
# Since we disable access to PHP files you
# can leave this on without worries.
# OR better yet, create a .htaccess file in
# the dir you want to allow browsing and
# set it to +Indexes
Options -Indexes
Options +FollowSymLinks
# Set the default file for indexes
DirectoryIndex index.php
<IfModule mod_rewrite.c>
# mod_rewrite rules
RewriteEngine on
# If a controler can't be found - then issue a 404 error from PHP
# Error messages (via the "error" plugin)
# ErrorDocument 403 /index.php/403/
# ErrorDocument 404 /index.php/404/
# ErrorDocument 500 /index.php/500/
# Deny any people (or bots) from the following sites: (to stop spam comments)
# RewriteCond %{HTTP_REFERER} nienschanz\.ru [NC,OR]
# RewriteCond %{HTTP_REFERER} porn\.com
# RewriteRule .* - [F]
# Note: if you are having trouble from a certain URL just
# add it above to forbide all visitors from that site.
# You can also uncomment this if you know the IP:
# Deny from 192.168.1.1
# If the file is NOT the index.php file
RewriteCond %{REQUEST_FILENAME} !index.php
# Hide all PHP files so none can be accessed by HTTP
RewriteRule (.*)\.php$ index.php/$1
# If the file/dir is NOT real go to index
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [QSA,L]
</IfModule>
# If Mod_ewrite is NOT installed go to index.php
<IfModule !mod_rewrite.c>
ErrorDocument 404 index.php
</IfModule>
P.S. I think that I didn't get quite clearly your problem with .php files. But if you haven't already, you'd look at native CI routing system it may solve your problem with another approach)
Let’s start with our big URL:
http://mycustomproject.com/index.php/webpages/view/my-url-title-of-the-post
The first thing that you usually do for your Codeigniter project is to remove the index.php file from the URL. To do it so, it’s really easy:
1st step
Add this code to your .htaccess file to your root of your project.
<IfModule mod_rewrite.c>
# Turn on URL rewriting
RewriteEngine On
# If your website begins from a folder e.g localhost/my_project then
# you have to change it to: RewriteBase /my_project/
# If your site begins from the root e.g. example.local/ then
# let it as it is
RewriteBase /
# Protect application and system files from being viewed when the index.php is missing
RewriteCond $1 ^(application|system|private|logs)
# Rewrite to index.php/access_denied/URL
RewriteRule ^(.*)$ index.php/access_denied/$1 [PT,L]
# Allow these directories and files to be displayed directly:
RewriteCond $1 ^(index\.php|robots\.txt|favicon\.ico|public|assets|css|js|images)
# No rewriting
RewriteRule ^(.*)$ - [PT,L]
# Rewrite to index.php/URL
RewriteRule ^(.*)$ index.php/$1 [PT,L]
</IfModule>
After the creation of the .htaccess file your project structure will have to look like this:
website_folder/
–––– application/
–––– assets/
–––– system/
–––– user_guide/
---- .htaccess <-------------------------
–––– index.php
–––– license.txt
2nd step
Now go to : application/config/config.php and change the:
$config['index_page'] = 'index.php';
to
$config['index_page'] = '';
So now your URL will look like this:
http://mycustomproject.com/webpages/view/my-url-title-of-the-post