rewrite from htaccess to codeigniter controller - .htaccess

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?

Related

Is there a way to properly redirect or rewrite vistors in my drupal 8 website to a subfolder?

I have the following code in my .htaccess file:
RewriteEngine on
RewriteCond %{HTTP_HOST} mysitedomain\.com [NC]
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^(.*)$ /web/$1 [L]
I'm currently using CPanel and CPanel does not allow you to set a new Document Root. So have my drupal files in my CPanel "public_html" directory with the composer.json files etc..and web directory that has all the Drupal related files. I am trying to get the site vistors to rewrite or redirect to www.mysitedomain.com/web for subsequent pages.. I tried the code below but does not seem to work.. Am i missing something?
To be specific.... I need the site to 1. load www.mysitedomain.com/web when www.mysitedomain.com is requested. 2. And ensure /web is is front of every subsequent request page request within the site (ie. www.mysitedomain.com/web/products should load instead of www.mysitedomain.com/products)
I am not sure what your question is, but I think you need something like this:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
What it does: If the URL does not resolve to a file or directory in the present directory, put index.php in front of it.
I'd assume your index.php would then include the Drupal framework.

skip directory in URl by using Rewriting Rules

I have a web-page with is located in example/files/page.php in my server. I would like to use Rewrite Rules in order to skip the /files directory in the URl so when the user types example/page.php to be able to view the content of the page.php. How is it possible to do so with Rewrite Rules?
Add this to the .htaccess in the root directory of your website.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d # not a dir
RewriteCond %{REQUEST_FILENAME} !-f # not a file
RewriteRule ^(example)/(.*)$ /$1/files/$2 [NC,L]

htaccess rule to redirect user without page name

My index.php page redirect to this type of url after process results.php?token=0e635edc03.
Now I would to to hide the results.php. So just: domain.com/0e635edc03.
Do I need a .htaccess rule ?
Which .htaccess rule I need to perform it ?
Thanks.
Try adding this to the htaccess file in your document root:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([0-9a-f]+)$ /results.php?token=$1 [L,NC]
now you need to make sure the index.php file redirects to domain.com/0e635edc03 instead of the results.php URL.

htaccess issue not working properly

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]

rewrite url in codeigniter

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";

Resources