I was using Capistrano to deploy my CI3 site and don't know much about rewrite rules. I was able to find htaccess rules from stackoverflow but none of them work for my case, so here I am.
I managed to have my home page running without any program, but none of the route works for me. They all return CI3 404 page not found error.
My Site Structure:
|-- .htaccess (under domain root)
|-- app/
|-- current/ -> symlink to latest release folder
|-- application/
|-- public/
|-- index.php
|-- .htaccess (under project root)
|-- ...other CI 3 folders and files
|-- shared/
|-- repo/
|-- shared/
|-- releases/
.htaccess ( under domain root )
RewriteEngine On
RewriteBase /
# remove www
RewriteCond %{HTTP_HOST} !^siteurl.com$
RewriteRule ^(.*)$ http://siteurl.com/$1 [L,R=301]
# redirect to CI3 root
RewriteCond %{REQUEST_URI} !^/app/current/
RewriteRule ^(.*)$ /app/current/$1 [L]
.htaccess ( under project root )
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
config.php
$config['base_url'] = 'http://siteurl.com';
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
routes.php
$route['default_controller'] = 'welcome';
$route['api/oauth'] = 'api/oauth';
So far, the welcome page works fine, but CI3 404 error page return for route api/oauth.
Please help!!! Many thanks!!!
I just figure it out, it is a stupid mistake, the controller name is all cap, CI3 not able to understand it. Problem resolved. The .htaccess code works.
Related
I made a VirtualHost to access to a php file and I want to allow access to this page and files in folder1.
Here are my folders :
root
|mywebsite.php
|.htaccess
|otherfiles
|
|--images
| |image.jgp
|
|--style
| |style.css
|
|--folder1
| |a_lot_of_folders
I can deny the access to the otherfiles in the root directory. If the URL is : www.ipaddress/ or www.ipaddress/otherfiles it will redirect to www.ipaddress/mywebsite.php.
But what I want is allow access only to the php file and files in folder1. But if the URL looks like this : www.ipaddress/folder1 or this : www.ipaddress/style it will open the Index of /folder and I don't want this.
Here is my .htaccess :
RewriteEngine on
RewriteRule ^$ mywebsite.php
RewriteRule ^otherfiles$ mywebsite.php # This is for each files in the root folder except the php one
RewriteRule ^/folder1? mywebsite.php # This doesn't work
I tried to rewrite the URL when it has /folder1 but it does nothing
Try this as your last rules:
RewriteRule ^folder1/?$ mywebsite.php [L,NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^folder1/ mywebsite.php [L,NC]
I think there are many htaccess redirect samples but I can't find a case similar to mine.
I have many sub folder my root
/suppliers
|- /suppliers/abc
|- /suppliers/xyz
/merchants
|- /merchants/abc
|- /merchants/xzy
etc.
I want to redirect them when I type
/m/yyy -> /merchants/yyy/index.php
/m/yyy/abc -> /m/merchants/yyy/abc.php
/m/yyy/abc/ -> /m/merchants/yyy/abc/index.php
Can anyone advise me on how I can do that?
You may use these rules in site root .htaccess:
RewriteEngine On
# /m/yyy rule
RewriteRule ^m/([\w-]+)/?$ merchants/$1/index.php [L,NC]
# /m/yyy/abc rule
RewriteRule ^m/([\w-]+)/([\w-]+)$ merchants/$1/$2.php [L,NC]
# /m/yyy/abc/ rule
RewriteRule ^m/([\w-]+)/([\w-]+)/$ merchants/$1/$2/index.php [L,NC]
I am developing on my localhost and i have a structure like so:
|public_html
| .htaccess
| [pagefolder]
| ......index.php
| ......[adminfolder]
| .............htaccess
| .............admin.php
As you can see, i decide it not to go crazy on .htaccess files. Just 2 is enough. One on my root and one on my protected admin folder.
when the url is localhost i just do the following on my root .htaccess to display the initial page:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^/?$ pagefolder/index.php [L]
When i want to access the admin panel (url: localhost/admin), i just do:
RewriteRule ^admin/?$ pagefolder/adminfolder/admin.php [L]
So far so good (i think). I run into problems when im using the .htaccess in the [adminfolder]
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^award/?$ admin.php?v=award [L,QSA]
When i go url: localhost/admin/award i get error:
The requested URL /admin/award was not found on this server.
However, the rule in the [adminfolder] looks ok to me. Im guessing something is missing, but not sure what?
None of your rules match /admin/award.
Your last rule redirects /pagefolder/adminfolder/award to /pagefolder/adminfolder/admin.php?v=award.
You can fix this by redirecting more admin URLs:
RewriteRule ^admin(/.*)? pagefolder/adminfolder/$0 [L]
Then change your adminfolder .htaccess:
RewriteRule ^admin/?$ admin.php [L,QSA]
RewriteRule ^admin/award/?$ admin.php?v=award [L,QSA]
I'm having trouble with .htaccess config...
List files and folders content:
/
src/
css/
admin/styles.css
user/styles.css
js/
admin/init.js
user/init.js
I want to access the file/folder path will matching paths rewrite
http://domain/src/css/staff/styles.css => src/css/admin/styles.css
http://domain/src/css/styles.css => src/css/user/styles.css
http://domain/src/js/staff/styles.js => src/js/admin/init.js
http://domain/src/js/styles.js => src/js/user/init.js
And here is my code:
RewriteRule ^src/staff/(.*)$ src/admin/$1 [L]
RewriteRule ^src/(.*)$ src/user/$1 [L]
But apparently things not working, there was an error has occurred "500 Internal Server Error".
If you just take a look at my problem and share a bit of your science, I'd be very grateful. Thanks!
With more regex matching you can use these 2 rules:
RewriteEngine On
RewriteBase /
RewriteRule ^(src)/(js|css)/staff/([^/.])+\.(css|js)$ $1/$2/admin/$3.$4 [L,NC]
RewriteRule ^(src)/(js|css)/([^/.])+\.(css|js)$ $1/$2/user/$3.$4 [L,NC]
Current directory structure:
wwwpublic
|+ spanish(language)
|-- index.php
|-- contact.php
|
|- index.php
|- aboutus.php
|- products.php
|- contact.php
In the root of wwwpublic directory I have files in the English language. Since site have Spanish language too, I have created separate directory named 'spanish'. Name of pages are exactly the same in both directories.
Now, some pages in spanish directory don't exist and I need to redirect request to such pages to root folder and retain name of file requested.
Example:
Visitor go to Spanish version, open index.php there, then he clicks on aboutus.php page (dont exists) inside spanish directory and then .htaccess redirects him to the /root/aboutus.php
Try something like this in your wwwpublic directory, preferably before any routing rules you may have:
RewriteEngine On
# conditions to check that current request doesn't point to a valid resource
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# condition to check that request is for the /spanish/ directory
RewriteCond %{REQUEST_URI} ^/spanish/(.+)$
# conditions to check if the /spanish/ is removed whether it would point to a valid resource
RewriteCond %{DOCUMENT_ROOT}/%1 -f [OR]
RewriteCond %{DOCUMENT_ROOT}/%1 -d
# all conditions match, rewrite
RewriteRule ^/?spanish/(.+)$ /$1 [L]