Moving Codeigniter Project to Amazon EC2, htaccess and ModRewrite Problems - .htaccess

I am attempting to move my Codeigniter projects from a shared hosting service to Amazon EC2 and am running into some challenges with my .htaccess settings. These settings enabled me to not have to include index.php in the url. My previous .htaccess is shown below and worked as expected with my previous hosting provider:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /simple.com/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
With my Amazon EC2 instance, I now have full access to the LAMP stack and have confirmed that the Apache Mod_Rewrite module is enabled.
I have set up my EC2 instance with two Virtual Host directories, one for each of my sites. Both sites serve up their CI applications as expected, but require index.php to be in the url.
I've tried inserting my Amazon EC2 public path into the .htaccess file as follows but still no luck:
RewriteBase /ec2-55-27-191-14.compute-1.amazonaws.com/simple/
I am sure this is 100% user error on my part and would greatly appreciate your diagnosis!

To answer my own question...
I wound up changing the Apache file /etc/apache/sites-available/default from AllowOverRide = None to AllowOverRide = All.

have you also tried
RewriteBase /
or RewriteBase /simple/
or along those lines?
in my dealings on servers i've used, i've never had to put the domain into the rewrite base. Just the folders

Related

Why is rewrite not working to mask an URL?

I have a page with an url like this:
https://example.net:9000/something
I want to be able to access it from here https://example.net/mysite
and mask the url as well so it will always show everything like this before the last /
I tried like this:
RewriteRule ^:9000/something/?$ /mysite/
but it didnt work. Why?
also, I have some other rules on my htaccess that have to stay unaltered:
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule \.(jpeg|jpg|gif|png)$ /public/404.php [NC,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L] <---everything up to this point has to stay the same
RewriteRule ^:9000/something/?$ /mysite/
</IfModule>
Thank you.
https:/example.net/ and https://example.net:9000 hare two separate http hosts that have nothing to do with each other. So you'd actually need the server for https:/example.net/ to proxy requests meant to be relayed to https://example.net:9000.
Assuming that https:/example.net/ is served by an apache http server (due to how you ask your question), this should be possible using the apache proxy module, either directly:
ProxyRequests off
ProxyPass /mysite/ https://example.com:9000/something/
ProxyPassReverse /mysite/ https://example.com:9000/something/
( Yes, indeed ProxyRequests off and not onif you implement this in the central server configuration. Leave that line away if you only have access to dsitributed configuration files (".htaccess") )
... or via the rewriting module:
RewriteEngine on
RewriteRule ^/?mysite/(.*)$ https://example.com:9000/something/$1 [P]
For that the proxy module and the proxy_http modules have to be loaded in the http server, obviously. The rule has to be implemented in the configuration of the http host serving https:/example.net/. If you do not have access to that you can instead implement it in the distributed configuration file (typically called ".htaccess") located in the DOCUMENT_ROOT of that host.

resolving index.php issue at url laravel htaccess

I know this question is asked alot and there are alot of answers on "how to resolve index.php issue in laravel".
However, I tried multiple ways in order to solve it from .htaccess on live dedicated server with WebsitePanel in order to remove index.php from URL. I tried a couple of ways however let me describe the issue here, index.php not only have changed the url, but also some of the css and javascript stuff are not loaded as well while most of them are loaded, CSS seems pretty fine but fonts are also changed.
It was working well at a shared host but here in a dedicated host it has alot of problems.
Is there a .htaccess code to solve this issue? and does index.php affects on CSS and is it normal?
my current htaccess is as follow:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
Options +FollowSymLinks
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ /index.php [L]
</IfModule>
You don't need to modify index.php or .htaccess. If you did this, revert to original files.
To remove index.php or public from URLs, you need to setup virtual host for Laravel project (there are instructions both for nginx and apache).
After that restart web server.
This is the most common problem in Laravel. When you upload your code to a webserver, your page will be in
www.web-something.com/index.php
So there are 2 things you should do,
1.Change the .htaccess file and also
2.Change the Virtual Host Settings in your server. Link :for setting up a virtual host in apache
After this you will be able to visit the directory just fine. Also about the CSS , problem , Its probably because of the virtual host settings. Itll get fixed up once you point everything to the right directory.
For IIS Windows Server, the .htaccess needs to be translated to web.config and this works like a charm.
here is the link:
How to enable modrewrite on IIS Web Server
In case Someone needed this in future!

How to deploy Symfony2 on a shared-hosting?

I want to access my symfony app in production env (http://www.sample.com/amateur1/web/app.php) from this url http://www.sample.com/amateur1.
To do that I moved the .htacces file to http://www.sample.com/amateur1/.htaccess with this contents:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /web/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]
</IfModule>
But when I go to http://www.sample.com/amateur1 shows a 404 Error, and prod.log isn't written.
I also used RewriteBase /amateur1/web/ because I don't know If RewriteBase path is relative to the DocumentRoot of the server, Or from the path where the .htaccess file is located. Also tried /amateur1 and /amateur1/ as RewriteBase due to this answer Symfony2: How to deploy in subdirectory (Apache)
With the three try's, The Exceptions page appears unstyled, and not loading any image. But then I get the following error in prod.log file:
[2013-02-15 02:06:47] request.ERROR: Symfony\Component\HttpKernel\Exception\NotFoundHttpException: No route found for "GET /amateur1/" (uncaught exception) at /home/u105859802/public_html/amateur1/app/cache/prod/classes.php line 5121 [] []
What I'm doing wrong ?
In your configuration, apache uses public_html as the document root
If Symfony2 is installed in directory /home/u105859802/public_html/amateur1, the Symfony public directory to serve is /home/u105859802/public_html/amateur1/web/
You should use
RewriteBase /amateur1/web/
But beware, it is not safe
You have to protect your symfony directories! (configuration is accessible)
Why don't you try moving your symfony files in your private area ?
You can rename the Symfony web directory to public_html
See how to do that in documentation cookbook
So, my recommendation structure looks like below :
/home/u105859802/
vendor
src
app
bin
public_html (web by default in symfony2) <- the only public directory
In most of the shared hosting, you can't override Apache settings in that case may need to wright a redirection rule in .htaccess file
Options +FollowSymLinks +ExecCGI
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?mydomain\.com$ [NC]
RewriteRule !^projectName/ /projectName/web/app.php/%{REQUEST_URI} [L,NC]
this is the rule I used in my project .
You may need to provide full paths to your assets other ways they will not get loaded .

CakePHP and .htaccess in shared hosting environment

Greetings!
I have CakePHP based app on shared hosting I wonder if there's a way to clean up the url through .htaccess. What bugs me is that I have to have index.php in it or I get a 404:
project.com/index.php/controller/method
Initially I was getting a 404 error no matter what and my host admin ended up setting RewriteEngine off and this is what it looks like now
<IfModule mod_rewrite.c>
RewriteEngine off
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
Is there fix for this without the .htaccess? As it is right now, does it pose any type of security risk?
Thanks
You need three .htaccess files :
/.htaccess
/app/.htaccess
/app/webroot/.htaccess
If the one you pasted in your question is the one at the root of your website, that's probably where your problem comes from. These directives file would rewrite URLs to project.com/webroot/, which doesn't exist. It should redirect to project.com/app/webroot/, which will in turn rewrite to index.php?url=$1 (relative to project.com/app/webroot/).
I'm not pasting the files here; the three of them are available in the CakePHP releases as well as in the Book: http://book.cakephp.org/2.0/en/installation/url-rewriting.html (check the 3rd item in the page).
Are you sure the mod_rewrite module is enabled on your shared hosting?

FreeBSD Server .htaccess issues

Server Details:
FreeBSD
PHP Version 4.3.11
Apache
Appache Modules:
mod_throttle, mod_php4, mod_speedycgi, mod_ssl, mod_setenvif, mod_so, mod_unique_id, mod_headers, mod_expires, mod_auth_db, mod_auth_anon, mod_auth, mod_access, mod_rewrite, mod_alias, mod_actions, mod_cgi, mod_dir, mod_autoindex, mod_include, mod_info, mod_status, mod_negotiation, mod_mime, mod_mime_magic, mod_log_config, mod_define, mod_env, mod_vhost_alias, mod_mmap_static, http_core
The issue I am having is when ever I write any kind of code in the .htaccess file, it throws a 500 Internal error
I am simply trying to rewrite url's and am using the exact code that wordpress creates for me and even tried custom code used before on previous servers and it still does not work.
WordPress created code:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /lobster-tail-blog/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /lobster-tail-blog/index.php [L]
</IfModule>
# END WordPress
And even a simple thing like this throws the error:
<IfModule mod_rewrite.c>
RewriteEngine On
</IfModule>
Anyone know of any fixes or why this is causing this error? I have the mod_rewrite module loaded
You should take a look at AllowOverride it is probably turned off try something like this:
<Directory /path/to/www/root/>
AllowOverride All
</Directory>

Resources