Before you tell me to go to CodeIgniter multi-application .htaccess problem, hear me out.
The reason I say that is because my problem seems to be nearly the exact same as this posters. My directory structure is:
application/
admin/
app/
..
.htaccess
admin.php
index.php
The htaccess rules are:
RewriteEngine On
RewriteBase /dev/
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^admin$ admin\.php [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^admin\/(.*)$ admin\.php/$1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index\.php/$1 [L,QSA]
Essentially what I need is:
type in example.com/admin - the url keeps the admin folder, and redirect the user to admin.php
type in example.com/admin/controller/method - same as above
type in example.com/anything_else - the user gets directed to the app instead of admin (index.php)
In testing the person in the aforementioned post's htaccess, which mine are essentially copied from, in an online tester, the two rules involving URIs with 'admin' in it are not passed for some reason. I can only get admin (not ^admin$) to work as a pattern (according to the tester).
RewriteRule ^dev/admin(\/?) admin.php? [L,QSA]
Should do it for you. This will account for /admin, /admin/ and /admin/whatever/here. But for the latter, be aware that since you have QSA on it will append it to the destination URL like so: /admin.php?whatever/here.
Related
In my index.php I have a list of properties. When I click on it, it directs me to property_detail.php but with extra details on the URL making it very long and untidy. How to make it short?
Set rewrite URL rule in .htaccess in the root folder.
RewriteEngine On
RewriteCond $1 !^(index\.php|assets|images|js|css|upload|favicon.png)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
I am writing a website which is dynamically populated through an Oracle database.
I have completed the desktop site and am now required to create a mobile site. Due to how different the sites are planned to look, I have opted to create 2 different "template" like websites for the mobile and desktop sites.
However, for my desktop site, everything is built off the index.php file in order to allow it to be completely dynamic. Pages are therefore look like www.domain.com/index.php/page in the url.
For the desktop site, this works. I am using a generic index.php removal rewrite rule in order to then make the url www.domain.com/page however still display the same page as the previous URL.
My issue, is that now I have a www.domain.com/mobile/index.php. Which has been created and for the most part has been working, however when trying to add addition dynamic pages to the mobile site. www.domain.com/mobile/index.php/about for example just redirects to www.domain.com/mobile/ and it doesn't even include the about part of the URL.
After much debugging, I have discovered it is definitely the .htaccess that is causing the issue.
If you have any insight into my issue, please help me out.
Thanks in advance
EDIT 1
Rewrite Rules are as follows
# Removes index.php from ExpressionEngine URLs
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteCond %{REQUEST_URI} !/system/.* [NC]
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]
# Directs all EE web requests through the site index file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
You can use this code in your /mobile/.htaccess file:
DirectoryIndex index.php
RewriteEngine On
RewriteBase /mobile/
RewriteCond %{THE_REQUEST} /index\.php [NC]
RewriteRule ^index\.php(?:/(.*))?$ $1 [L,R=302,NC,NE]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php/$1 [L]
This will override all the rules present in parent .htaccess for /mobile/ URI path.
Simplified version to make it work in root .htaccess:
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^(mobile)/(.*)$ $1/index.php/$2 [L,NC]
# Directs all EE web requests through the site index file
RewriteRule ^(.*)$ /index.php/$1 [L]
Based on the debugging you mentioned, there is a rule in your .htaccess which is rewriting www.domain.com/mobile/index.php/about to www.domain.com/mobile/. So, if you find which rule this is, you can add one above it that will catch requested URLs for your mobile pages and then not allow the problematic following rule to run. Something like this:
RewriteRule ^mobile/index.php/([a-zA-Z0-9-_]+)$ ^mobile/index.php/$1 [L,QSA]
The L ensures that if the user's request matches this rule, no further rules (including the one causing the issue) will be executed.
Thank you for the answers you've both given, however neither of them worked, I've now solved the issue, it was to do with the final RewriteRule at the end
# Directs all EE web requests through the site index file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
I needed to change it to
# Directs all EE web requests through the site index file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !/mobile/.* [NC]
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} /mobile/.* [NC]
RewriteRule ^(.*)$ mobile/index.php/$1 [L]
So that it would work with both mobile and desktop sites.
I have added into htaccess file some rules in order to remove index.php from the url in Code Igniter . However, for just one address it is not working
the url is like this "http://example.com/subtitle/eveythingelse/";
so when the second uri is "subtitle" or "sub" it doesn't send to "index.php" and directly reads the folder which doesn't exist.
if I change the second uri "http://example.com/changed/everythingelse" it works.
I am really confused about.
this is code of .htacce :
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
It's because with final /
RewriteCond %{REQUEST_FILENAME} !-d
Test if the directory exist, and don't do rewrite.
You can delete this condition.
I recently moved my codeigniter application from a subdomain to operate under my domain.
Basically I moved it from:
https://account.mywebsitehere.com
To:
https://mywebsitehere.com/account
Now when I try to access anything like /invoices it removes the /account from the url and results in a not found page. I have changed the base url in the config file but it is still resulting in this error.
Other than going through the entire application and changing every link to be /account/... How can I make the application work under the /account in the url?
My .htaccess file located at public_html/panda/.htaccess is as follows:
RewriteEngine on
RewriteCond $1
!^(index\.php|robots\.txt|files\/images|files\/css|files\/js|files\/swf|files\/upload)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://mywebsitehere.com/panda/$1 [R,L]\
Try to change base_url to:
$config['base_url'] = 'https://mywebsitehere.com/account';
just put that code in .htaccess file and try it
RewriteEngine On
RewriteBase /account/
RewriteCond %{REQUEST_URI} ^system.*
RewriteCond $1 !^(index\.php|images|js|uploads|css|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
first, upload an image to the root directory and see if you can access it within the browser.
if you cant access it , check your server's configuration and your .htaccess file.
I am developing the website in codeigniter with HMVC. I will have multiple subdomains which points to HMVC modules.
My current .htacess contains
DirectoryIndex index.php
RewriteEngine On
RewriteCond $1 !^(index\.php|themes|assets|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]
File structure
./application
/modules
/news_module
/mobile_module
/api_module
./system/
It works normal when typing
http://mysite.com/news_module/controller/method
http://mysite.com/mobile_module/controller/method
http://mysite.com/api_module/controller/method
But I want to redirect from
http://mysite.com/mobile_module/controller/method
to
http://m.mysite.com/mobile_module/controller/method
and hide (mobile_module) so finally
http://m.mysite.com/controller/method
In case sombody type
http://m.mysite.com/mobile_module/controller/method
also i want
http://m.mysite.com/controller/method
how can i do this in .htaccess?
for the first part of your question use:
RewriteCond %{HTTP_HOST} ^example.com$ [NC]
RewriteRule ^mobile_module/(.*) http://m.example.com/$1 [R=301,L]
Don't see how someone would just type m.mysite.com/mobile_module/_______