问题
i'm using Codeigniter for my web app, i changed the structure of the project as the following :
my_Project
--- application
--- public_html
--- resources
--- system
I created the folder public_html to seperate my public files from the classes .. etc, but now i have to call this url every time :
my_project/public_html/controller/action
i want it to be this way :
my_project/controller/action
I already moved out the index.php from the URL using the rewrite mode, but i can't seem to remove the public_html as well :
.htaccess
<IfModule mod_rewrite.c>
# Turn on URL rewriting
RewriteEngine On
# If your website begins from a folder e.g localhost/my_project then
# you have to change it to: RewriteBase /my_project/
# If your site begins from the root e.g. example.local/ then
# let it as it is
RewriteBase /uca-flsh/public_html
# Protect application and system files from being viewed when the index.php is missing
RewriteCond $1 ^(application|system|private|logs)
# Rewrite to index.php/access_denied/URL
RewriteRule ^(.*)$ index.php/access_denied/$1 [PT,L]
# Allow these directories and files to be displayed directly:
RewriteCond $1 ^(index\.php|robots\.txt|favicon\.ico|public|assets|css|js|images|resources|public_html)
# No rewriting
RewriteRule ^(.*)$ - [PT,L]
# Rewrite to index.php/URL
RewriteRule ^(.*)$ index.php/$1 [PT,L]
</IfModule>
.config.php
$config['base_url'] = 'http://localhost/uca-flsh/public_html';
回答1:
Try using this:
RewriteCond %{THE_REQUEST} /my_project/public_html/controller/action [NC]
RewriteRule ^ my_project/controller/action [L,R]
来源:https://stackoverflow.com/questions/38379387/rewrite-url-codeigniter