My codeigniter website current url is www.websitename.com/fronend/deals/index/all/all.
(note:frontend is folder inside controller, and deals is controller)
I wants to change it to www.websitename.com/deals/ using htaccess. I had tried some code but not able to do that.Is that possible to change it using htaccess.
Previously, I had removed the index.php from the url of my codeigniter site using following htaccess code.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
this is working fine.So I think, I needs to add some rewrite rule for this.
could u pls explain me how to do this.Thanks
you don't need htaccess
in
.\application\config\routs.php
add
$route['deals'] = "fronend/deals/index/all/all";
Related
I'm trying to redirect old site files toward new CodeIgniter site with .htaccess.
So, my old file
www.mysite.com/news/new?id=123
have to redirect to
www.mysite.com/news/new/123
For now, my .htaccess has inside usually code to remove index.php and it works fine.
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule ^(.*)$ index.php?/$1
But when I try the old file redirect nothing works.
I think the issue's about CodeIgniter, becouse if I make a simple redirect to an external file, like phpinfo.php it works fine, but if a try the redirect to index.php (of CodeIgniter) it doesn't load index.php but try to load other. Also does if I delete .htaccess code for index.php (see upside).
So,
RewriteRule news/new.php phpinfo.php [L] # it works
but
RewriteRule news/new.php index.php [L] # it doesn't work
Codeigniter use REQUEST_URI Apache variable that can not change with RewriteRule and without redirection. So you can use _remap function in news controller to call your custom method.
Other way that can be doing with htaccess is enabling query string.
Try
RewriteRule news/new\?id=(.*)$ index.php/news/new/$1 [L]
I have to do a very specific url redirect using mod_rewrite within an .htaccess. Below is a url which has to map to the url below it:
m.example.com/123456/123456-product-name/
This needs to map to the following:
m.example.com/product-name/123456
I'm still getting to grips with regex and url rewrites and I've spent a good couple of hours trying to get this right. Can anybody help!?
Thanks in advance
You can do that. in root .htaccess:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^\d+/(\d+)-([^/]+) /$2/$1 [R=301,L]
Or just [L] (and not [R=301,L]), if you do that without redirection.
I am using URL Rewriting in .htaccess file my problem is this in root folder I have index.php file and I am redirect to en/home/ folder but redirection is not working when I use this .htaccess code.
RewriteRule ^([^/]*+)$ en/peoples/globalCardDetail.php?p=$1
Rewriting is working fine like this http://www.domain.com/atiq ur rehman. But when I access my domain http://www.domain.com this is redirecting to this page en/peoples/globalCardDetail.php.
You need to change your regular expression from ^([^/]*+)$ to ^([^/]+)$.
Also, you may want to add some conditions:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)$ en/peoples/globalCardDetail.php?p=$1 [L]
I used this code in my .htaccess to rewrite my urls which is like this:
www.example.com/subcategory.php?subcat=my-test
to
www.example.com/my-test
.htaccess code I used:
RewriteEngine on
RewriteCond $1 !^(subcategory\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ subcategory.php?subcat=$1 [L,QSA]
My problem is whenever I access the url not pertaining to my subcategory.php file like contactus and aboutus, the .htaccess file will somehow put me to subcategory.php file which is not what I want. I want my contactus be handled by contactus.php and aboutus with aboutus.php.
I know that there is something wrong with my .htaccess file but I couldn't fix it by myself for I am not so familiar with the .htaccess coding.
Any suggestion would be greatly appreciated.
Thank you very much!
You are rewriting all requests to subcategory.php. There is no way for .htaccess to tell whether /xxx is a subcategory or some different page, so you could redirect it to a different script.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [L]
Use this code snippet instead of yours and move all the "routing" logic to PHP. In PHP, you can find out whether /xxx is a subcategory, a contact page, an article or something else and use a script suitable for that kind of database record.
You will find the requested URL in $_SERVER['REQUEST_URI'].
My codeigniter application directory structure is like
--application
--htdocs
--index.php
--.htaccess
--folder
--file1.xml
Now I have a url http://mysite.com/folder. This is showing the files list in the folder directory. What I want here is to rewrite this url to a controller on my site say 'html.php'.
Note: I do not want to redirect. I want the url to be same but instead of showing folder contents, I want to pass the control to a controller. What .htaccess rule should I write?
have you looked at url routing?
ie
$route['folder'] = "html"; //html is your controller
www.yoursite.com/folder
will "redirect" to yoursite.com/html but won't change the URL.
no need to mess with htaccess
edit:
RewriteEngine On
RewriteBase /
#ignored folders/files
RewriteCond $1 !^(index\.php|robots\.txt|img/|css/|js/)
RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
obtained from - http://codeigniter.com/forums/viewthread/153228/
perhaps this is what you are after?