CodeIgniter public_html remove slug - apache

i have problem to remove public_html slug in url
It look like this
http://shirodailynews.esy.es/public_html/about
But i want to be like this
http://shirodailynews.esy.es/about
My current .htaccess in public_html
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
My structure file is like this:
system
application
public_html
css
js
img
I also configured the system and application path like this
$system_path = '../system';
$application_folder = '../application';
When I access the main url it not showing the public_html
http://shirodailynews.esy.es/
but when I access the another link it redirect it using public_html slug.
http://shirodailynews.esy.es/public_html/about
How I remove the public_html slug in the url? Thanks in advance!

Seems like your webroot's not public_html, so precisely, you probably need to just put the index.php and the .htaccess file in the directory below it.

Related

htaccess redirect API to sub folder

My document root (/var/www/html/) looks like this:
app/
client/
index.html
server/
api/
user/
get.php
classes/
models/
When the user navigates to any URL on my website that does NOT start with api/, they should load the index.html file inside of client.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond ^ app/client/index.html [QSA,L]
That code works correctly.
However, when the URL starts with api/, I want to direct the URL to the api folder under server/.
For instance, www.website.com/user would load the index.html file.
Whereas www.website.com/api/user/get.php would load www.website.com/server/api/user/get.php.
I know that I would need a special condition for api/ before my current condition.
RewriteRule ^api app/server/api [L]
That rule works when using www.website.com/api, but it does not work when there are slashes after api/. www.website.com/api -> www.website.com/app/server/api, www.website.com/api/test -> www.website.com/var/www/html/test.
Any ideas?
Have it this way:
RewriteEngine On
RewriteRule ^api(/.*)?$ app/server/api$1 [L,NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond ^ app/client/index.html [L]
Make sure to test it after clearing your browser cache.

Removing specific path segments from url with .htaccess

My current url structure looks like this:
Served from /var/www/app:
/example.com/app/news
/example.com/app/files
/example.com/app/offers
Served from /var/www:
/example.com/admin
Slightly strange structure as I've bolted the 'app' onto a current CMS simply by creating a new app sub-directory in the root folder. What I want to do is to serve the app files from eg:
/example.com/news
/example.com/files
/example.com/offers
i.e. just removing app from the url. But I obviously still want the /admin/ routes to be served from the original root directory. How can I go about this?
You can try this:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/admin$
RewriteRule (.*) /app/$1 [L]
You will find the documentation here: http://httpd.apache.org/docs/2.4/mod/mod_rewrite.html

Yii framework: Using htaccess for site in sub directory not working on Hostgator

I'm trying to set up Yii site to be loaded from sub directory to root domain. In my root site folder I have only root .htaccess file and sub directory "subdir" which contains Yii site. I found a solution that works on my local environment:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) subdir/index.php/$1 [QSA,L]
But when I upload the site to HostGator it just does not work correctly
For example
if I use http://localhost/contact on my local environment, correct page is opened (called site/contact - site controller and contact action. I've added Yii 'contact'=>'site/contact' rule to the urlManager, so both http://localhost/contact and http://localhost/site/contact can work)
If I use http://mydomain.com/contact or (http://mydomain.com/site/contact) on HostGator, I get default index page (called site/index - site controller and default index action instead)
When I choose to access subsites directly like http://mydomain.com/subdir/contact it works fine, but it does not work if I use http://mydomain.com/contact
I guess that I need somehow to change this last rule in htaccess, but not sure how. Thanks!
I've found alternative solution that works. I was forced to use old fashioned URLs instead of paths, so I've changed my urlManager to:
'urlManager'=>array(
//'urlFormat'=>'path',
'showScriptName'=>true,
'caseSensitive'=>false,
'rules'=>array(
...
)
)
And my root htaccess looks now like this:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /subdir/index.php?r=$1 [QSA,L]
So, when accessing
http://mydomain.com/site/contact
Actual mapped URL is
http://mydomain.com/subdir/index.php?r=site/contact
which as result returns correct contact page
Since, you stated in your previous question that www.mysite.com/mysite/frontend/www/controller/action works fine; you should be using:
AddHandler application/x-httpd-php53s .php .html
Options +SymLinksIfOwnerMatch
IndexIgnore */*
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_HOST} ^(www.)?mysite.com$
RewriteCond %{REQUEST_URI} !^/mysite/frontend/www
RewriteRule ^(.*)$ /mysite/frontend/www/$1 [L]
You dont need to edit .htaccess. You just need to move the Yii entry script (index.php) and the default .htaccess up from the subdirectory to the webroot (so that they reside directly under public_html). Once you move index.php and .htaccess to the root directory, all web requests will be routed directly to index.php under webroot (rather than to the subdirectory), thus eliminating the /subdirectory part of the url.
After you move the files, you will need to edit index.php to update the references to the yii.php file (under the Yii framework directory) as well as the Yii config file (main.php). Lastly, you will need to move the assets directory to directly the webroot, since by default, Yii expects the assets directory to be located in the same location as the entry script).
That should be all you need to do, but if you need more details, I describe the approach fully here:
http://muhammadatt.tumblr.com/post/83149364519/modifying-a-yii-application-to-run-from-a-subdirectory

mod_rewrite -> doesn't work as expected

i use the following .htaccess to redirect all requests to my index.php except if a folder or file exists.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?uri=$1 [QSA]
But if i try url's like domain.com/thing/a/thing/b i get redirected to my index.php but everything else is messed up. The html doesn't link properly to the stylesheet and so on.
My application is working kinda like a MVC-Framework, i.e. everything happens over the index.php. So i don't want that other files are accessible except files in a public folder and some specific files. Namely cron.php in the root and some css/js/image files down the folder structure.
More details on the file structure: https://bitbucket.org/BrainInBlack/source-motd-plus/src
Or do i have to link stylesheets and other stuff with absolute paths, i.e. "http://domain.com/path/to/style.css" and so on?
use a slash client before (.*)$ index.php?uri=$1.
use this code:
RewriteRule ^/client(.*)$ index.php?uri=$1
You either need to change all your links to absolute links or add a
<base href="http://domain.com/">
to the header of your pages.

Codeigniter .htaccess: Give public access to all files and folders inside the 'public' folder

I'm using Codeigniter 2.0.3 | Apache 2.2.17 | PHP 5.3.4.
I'm want to give access to all the files and subfolders inside the 'public' folder. I've read the articles in the Codeigniter wiki and also all first 5 pages on google results and found nothing that works.
This is the files tree:
- application
- public
- css
- style.css
- img
- js
- system
- .htaccess
And this is the .htaccess I'm using to remove 'index.php' from the URL and try to give access to the folder:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /CodeIgniter_2.0.3
#Removes access to the system folder by users.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php/$1 [L]
#Checks to see if the user is attempting to access a valid file,
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#Enable access to the images and css folders, and the robots.txt file
RewriteCond $1 !^(index\.php|public|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
The website is working and 'index.php' is no longer needed in the URL, but the last condition is supposed to give access to the public folder, but its not working for me, so this http://localhost/CodeIgniter_2.0.3/public/css/style.css
file is not found.
In config.php I have:
$config['base_url'] = 'http://localhost/CodeIgniter_2.0.3/';
$config['index_page'] = '';
Please help.
Thanks!!!
With your current structure, you need to change the last RewriteCond to:
RewriteCond $1 !^(index\.php|application\/public|robots\.txt)
because your .htaccess is in the same directory as your application folder and your public folder is in your application folder, you need to explicitly mark the application/public folder as accessible.