Change the url in codeigniter - .htaccess

My url like
http://localhost/message/Welcome/index
But i like to show
hhttp://localhost/message/index
remove the controller name
My routes
$route['default_controller'] = 'welcome';
$route['index'] = 'welcome/index';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
And try this one
$route['message/send'] = "message/welcome/send";
My htaccess
<IfModule authz_core_module>
Require all denied
</IfModule>
<IfModule !authz_core_module>
Deny from all
</IfModule>
Please help me to remove the controller in the middle of url .
Thanks in advance!!!!

You can do that simply using your .htaccess file. Add the following rule:
RewriteEngine On
RewriteRule ^(.*)/Welcome /$1 [R=301,L]
That will remove /welcome from your URL using a 301 redirection. Leaving you with: http://localhost/message/index
Make sure you clear your cache before testing this.

Related

Unable to host codeigniter project in a web server

I have created a web project in codeigniter. In my localhost (windows 7) I could run the project with no errors. But when I try to host my project in my university subdomain (the administrator gave me a subdomain to host my files myproject.university.edu.bt). I uploaded all my files via filezilla. When I try to access my page, which starts with a login page. It displays the login button without any of the styles that I have coded for the site. When clicking the login button instead of displaying the next page it gives me an error The requested URL /sasec/login/user_login was not found on this server. Can anybody tell me what I should do to view/display my pages correctly! Here is my .htaccess file. The university server is running on linux
<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>
<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>
Go to config/routs.php
Change this
$route['default_controller'] = '';//give your default controller name
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
in addition
Path - config/config.php
$config['base_url'] = '';
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
You will have to probably change something with
RewriteBase /
in your htaccess file, link given below will give you more idea.
https://www.daniweb.com/web-development/php/threads/435526/codeigniter-remove-index-php-while-working-on-virtual-host-on-xampp
Thanks
Amit

How to rewrite part of URL in .htaccess?

I have this URL:
example.com/news/article/254
How to make a PHP script to process this URL (example.com/blog/article/254) as example.com/news/article/254,
and example.com/blog as example.com/news, etc.
The following code should work if you add it to your .htaccess file.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^blog/article/(.+?)\/?$ /news/article/$1 [R=301, L]
</IfModule>
If you don't want to tell robots etc. that you have permanently redirected then take out the "R=301, " above.

How to setup Subdomain directories with .htaccess

I have subdomain, got error 404 while clicking on links. I want to be able to click on each link without getting any error messages. How can I setup the .htaccess file? currently using codeIgniter.
Here's the situation
Ex:
mysubdomain.website.com -> mysubdomain.website.com/gallery1 = display error 404
mysubdomain.website.com -> mysubdomain.website.com/gallery2 = display error 404
NB: BTW I Don't want to redirect mysubdomain.website.com to website.com/mysubdomain/gallery1
Any helps migh appreciate
Thanks in advance!
My .htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond $1 !^(index\.php|images|phpmyadmin|robots\.txt|ckeditor|css|js|favicon\.png|captcha|img|uploads)
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
Anything other than given values "images", "phpmyadmin" etc. will be looked up in config/routes.php
So:
http://127.0.0.1/css/style.css
Will return file at www/css/style.css
http://127.0.0.1/anything
will be taken as CodeIgniter link
Edit: Don't forget to update your config file with
$config['index_page'] = '';

How to redirect in .htacces &Itemid=x to &Itemid=Y

Hello I have this issue
I cant redirect this
index.php?option=com_adsmanager&view=list&catid=8&Itemid=435
To this
index.php?option=com_adsmanager&view=list&catid=8&Itemid=565
catid=8 is a variable i need redirect all the catid= values
Im only need to chanche &Itemid=435 to &Itemid=565
I have this code
RewriteEngine on
RedirectMatch 301 ^(.+)\&Itemid=435$ $1&Itemid=565
I dont know what is wrong
I need all the urls anything&Itemid=435 goes to sameanything&Itemid=565
Alternative
Add below PHP Code at the top of index.php or configuration.php of Joomla!
It checks for numerical catid & Itemid requests & if Itemid=435 It will redirect URL with catid & new Itemid. Feel free to modify code according to your need!
if(isset($_GET['catid']) && is_numeric($_GET['catid']) && isset($_GET['Itemid']) && is_numeric($_GET['Itemid']))
if($_GET['Itemid'] == 435)
{
$catid = $_GET['catid'];
$location = "/index.php?option=com_adsmanager&view=list&catid=$catid&Itemid=565";
header ('HTTP/1.1 301 Moved Permanently');
header ('Location: '. $location);
}
Answer - 2
I assumed that you wants is to redirect URI-1 to URI-2.
index.php?option=com_adsmanager&view=list&catid=8&Itemid=435
index.php?option=com_adsmanager&view=list&catid=8&Itemid=565
Below mod_rewrite will let you redirect specific URI to other specific URI.
Just add below rules in .htaccess file.
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{QUERY_STRING} ^option=com_adsmanager&view=list&catid=8&Itemid=435$
RewriteRule ^/?index\.php$ /index.php?option=com_adsmanager&view=list&catid=8&Itemid=565 [R=301,L]
</IfModule>
Answer - 3
Use below in your .htaccess, if you want to handle requests with'/index.php' and '/'.
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{QUERY_STRING} ^option=com_adsmanager&view=list&catid=8&Itemid=435$
RewriteRule ^(.*)$ /index.php?option=com_adsmanager&view=list&catid=8&Itemid=565 [R=301,L]
</IfModule>
NOTE: Do not use both code in single .htaccess file.

403 error when access controller in subfolder (CodeIgniter)

This is my application skeleton:
application
controllers
backend
[backend_controllers_here]
[frontend_controllers_here]
models
[shared_models_for_both_backend_and_frontend]
views
backend
[backend_views_here]
[frontend_views_here]
...
system
index.php
.htaccess
This is my .htaccess file content:
Options -Indexes
Options +FollowSymLinks
# Set the default file for indexes
# DirectoryIndex index.php
<IfModule mod_rewrite.c>
# activate URL rewriting
RewriteEngine on
# do not rewrite links to the documentation, assets and public files
RewriteCond $1 !^(images|assets|uploads|captcha)
# do not rewrite for php files in the document root, robots.txt or the maintenance page
RewriteCond $1 !^([^\..]+\.php|robots\.txt)
# but rewrite everything else
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>
It's nothing wrong when I type on address-bar something like these (for frontend):
mysite.local
mysite.local/index.php
mysite.local/index.php/frontend_controller
mysite.local/frontend_controller
But for backend I had a 403 error when try to access:
mysite.local/backend
mysite.local/backend/some_backend_controller
However, with index.php in URL everything is fine.
mysite.local/index.php/backend
mysite.local/index.php/backend/some_backend_controller
Am I missing something here?
Thanks for your time!
check the permission for the backend folder. it maybe prevents the webserver from reading the actual content of the directory.
The permission should allow reading for everyone
What does your config/routes.php look like? Might try something like this:
$route['backend'] = "backend/controller/method";

Resources