I’ve got Codeigniter on Ubuntu 10 (LAMP). I have an htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /dort
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php
#controller, previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /dort/index.php?/$1 [L]
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends
#the request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /dort/index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin
ErrorDocument 404 /index.php
</IfModule>
Up until now, we connected the remote server with an IP address,my base site is sitting under a folder called
‘dort’, so we used to call it like this: http://some_ip/dort
now we mapped a virtual host to dort, so we call it like: http://demo.dort.com/ and suddenly nothing
works except for the login page (index.php). I’ve changed $config[‘base_url’] in config.php but i
keep getting 404.
Please help :(
Did you use virtual host?
I have same problem and solve with this
1) Make virtual host in my case is like this: file /etc/apache2/sites-available/default
<VirtualHost *:80>
ServerAdmin admin#email.com
DocumentRoot /var/www/dort
ServerName yourdomain.biz #this domain must be define tld info.
ErrorLog /var/log/apache2/error_2.log
<Directory /var/www/dort>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
# Uncomment this directive is you want to see apache2's
# default start page (in /apache2-default) when you go to /
#RedirectMatch ^/$ /apache2-default/
</Directory>
</VirtualHost>
2) Setting host in file /etc/hosts
127.0.0.1 localhost
127.0.0.1 yourdomain.biz
# The following lines are desirable for IPv6 capable hosts
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
3) .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# Send admin URL's to the admin controller (then skips the rest of the redirect rules)
RewriteCond %{REQUEST_URI} ^/admin(.*)
RewriteRule ^(.*)$ /index.php/admin/$1 [L]
# Redirects any request thats not a file or directory through to the main controller
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/main/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
ErrorDocument 404 /index.php
</IfModule>
4) Make sure when restart apache not show error
Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
5) Go to browse and run this url http://yourdomain.biz
Above solution worked for me. I just want to highlight one thing. Make sure you have AllowOverride All instead AllowOverride None in virtual host file at /etc/apache2/sites-available/default
Related
LARAVEL 5.0 | APACHE 2.4.7 | PHP 5.5.8
I know this is a pretty popular question. A lot of people saying to move public contents to root directory (which i find awkward because of security issues), rewriting the .htaccess, creating virtual host.
I tried creating virtual host because i think this is more acceptable solution.
but i'm encountering some problems with my configurations:
I'm running easyphp for the meantime, id like to test if i can get rid of the public route in url before setting this up live.
httpd.conf
NameVirtualhost *:80
<VirtualHost *:80>
DocumentRoot "${path}/data/localweb/quantum.dev/public"
ServerAdmin admin#localhost
ServerName quantum.dev
ServerAlias www.quantum.dev
<Directory "${path}/data/localweb/quantum.dev/public">
AllowOverride All
Options Indexes FollowSymLinks
Order deny,allow
Allow from quantum.dev
Deny from all
Require all granted
</Directory>
</VirtualHost>
I modified C:\Windows\System32\drivers\etc
hosts
127.0.0.1 quantum.dev
When I try to browse http://127.0.0.1/quantum.dev/ it will load the listof files and not the project inside public
http://127.0.0.1/quantum.dev/
Please revert all your changes to the directory. restore the default structure and configuration of the project. If i'm not mistaken and correct me if i am, you are using a shared hosting provider. If that is the case, here is a more proper way of doing so.
In your .htaccess, you need to add the following.
At the top of the file add this line:
DirectoryIndex public/index.php
and in here:
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
Change the last rule to this:
RewriteRule ^ public/index.php [L]
Now, all you need to do is to move this, and only this(the .htaccess file), to the root folder of your project. In this way, you are maintaining the laravel project structure in its original state.
put this .htaccess file near public folder
Options -MultiViews
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
When you are selecting a directory for your domain in c-panel, simply provide path till the Laravel's public directory and not just till the Laravel's root directory. That way you don't need to change .htaccess at all.
I have just recently upload my site to the production and follow above steps. It worked very well.
This is my configuration that is working fine for me. So first of all, your Virtual host configuration should be like that :
ServerAdmin webmaster#domaine.dev
ServerName domaine.dev
DocumentRoot /var/www/mysiteweb/public/
<Directory /var/www/mysiteweb/>
Options -Indexes
DirectoryIndex index.php index.html
AllowOverride All
</Directory>
Anf after, make this on your .htaccess laravel file :
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
Don't forget to check if the mod_rewrite is enable.
Hope that helped. Regards.
our dev environment at work uses a single centos machine with apache/php that serves different virtual hosts for both CIFS mounted and local directories. our application is built using CodeIgniter 2.0
we recently made a change to our Routes that is working fine for the virtual hosts serving the mounted drives, but the routes cannot be resolved for local files, resulting in a 404.
$config['base_url'] = "http://production.host.com"; // the production value of $_SERVER['SERVER_NAME'] essentially
routes:
$route['companyone'] = 'sso/platformsso/requestgenericsso/companyone';
$route['companyone/(:any)'] = 'sso/ptlatformsso/requestgenericsso/companyone/$1';
this works for the following scenario:
<VirtualHost 192.168.1.1:80>
ServerAdmin me#host.com
DocumentRoot "/var/mnt/a"
ServerName "a.tmbc.com"
ErrorLog logs/a.error.log
Alias ssaml /var/simplesamlphp/www
</VirtualHost>
<Directory "/var/mnt/a">
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
Directory populated using CIFS mount: mount -t cifs //1.2.3.4/a /var/mnt/a -o rw,username=un,password=pwd,uid=48 --verbose1
but does not work for this scenario:
<VirtualHost 192.168.1.1:80>
ServerAdmin me#host.com
DocumentRoot "/var/www/html/b"
ServerName "b.host.com"
ErrorLog logs/b.error.log
Alias ssaml /var/simplesamlphp/www
</VirtualHost>
<Directory "/var/www/html/b">
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
Directory populated using SVN checkout: svn checkout file:///var/svn/repo/trunk /var/www/html/b
.htaccess:
AddType text/x-component .htc
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# Restrict unused HTTP methods
RewriteCond %{REQUEST_METHOD} !^(GET|POST|HEAD)
RewriteRule .* - [R=405,L]
# Forces SSL
RewriteCond %{HTTPS} !=on
RewriteRule ^.*$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
#Removes access to the system folder by users.
RewriteCond %{REQUEST_URI} ^_sys.*
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteCond %{REQUEST_URI} ^_app.*
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteRule ^(.*).(pdf|exe|doc|mp4)$ /externaldownload/?fileLocation=$1.$2 [R,L]
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
any ideas of why this is so?
I think I understand your issue here. Problem seems to be on (:any) your route rule.
$route['companyone/(:any)'] = 'sso/ptlatformsso/requestgenericsso/companyone/$1';
A URL with companyone as the first segment of URL and anything for the second segment will be remapped to sso/ptlatformsso/requestgenericsso/companyone/$1
It seems like codeigniter passing $1 as a variable to the function companyone which means you are actually matching any route there to forced to rewrite.
How about condensing those to route rules and make a
$route['(.*)'] = "sso/ptlatformsso/requestgenericsso/companyone/$1";
or have only one rule there for routes such as
$route['companyone/(:any)'] = 'sso/ptlatformsso/requestgenericsso/companyone/$1';
I'm trying to find a way to solve my problem but I don't find any solution. I'll try to explain the better I can.
I'm developing my website in a local environment, on a MAMP server. The home URL is http://localhost:8888/mysite/web/app_dev.php. I wanted to change it to http://site.dev for the dev mode (later, I will use http://site.prod for the prod mode). Some of you will ask me "why ?". The answer is that we want (the other developers and I) to have the same kind of URL than in my production like http://example.com
So, I looked on the side of the Apache's virtual hosts and the host file on my computer. I changed the Apache port to 80 and the MySQL port to 3306 (Nginx is 80 by default too).
Here is the httpd-vhosts.conf file :
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot /Applications/MAMP/htdocs
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
ServerName site.dev
ServerAlias www.site.dev
DocumentRoot /Applications/MAMP/htdocs/site/web
<Directory /Applications/MAMP/htdocs/site/web>
AllowOverride All
Order Allow,Deny
Allow from All
</Directory>
</VirtualHost>
The hosts file :
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
fe80::1%lo0 localhost
127.0.0.1 site.dev
Obviously, I activate the vhosts in my apache httpd.conf file :
# Virtual hosts
Include /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf
Here is my new web/.htaccess file :
DirectoryIndex app_dev.php
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^app\.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^app_dev\.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .? - [L]
RewriteRule .? %{ENV:BASE}/app_dev.php [L]
</IfModule>
<IfModule !mod_rewrite.c>
<IfModule mod_alias.c>
RedirectMatch 302 ^/$ /app_dev.php/
</IfModule>
</IfModule>
Now, I go on http://site.dev, everything works fine.
I make a changement in my script.js file (for example), then, I refresh my home page. Nothing changed... I try to execute php app/console assetic:dump, I refresh one more time, and, miracle, everything works.
So, my question is the following one : How can I use my http://site.dev virtual host WITHOUT the need of executing the assetic:dump console function.
Thank you
EDIT : I didn't find a solution to my problem, so, I will give you more details :
- When I go on http://localhost/site/, I see all the directories and files of the root directory.
- When I go on http://localhost/site/web/, all the website is displayed but there are missing images (bad path in twig or less files) and I have to execute assetic:dump.
- When I go on http://localhost/site/web/app_dev.php, everything is refreshed instantly...
php app/console assets:install web --symlink
This should symlink your assets, so you wont need to re-run the asset command each time .
Also, check out http://symfony.com/blog/new-in-symfony-2-6-smarter-assets-install-command
On my local machine, the symfony project I have created works perfectly.
I have installed symfony on my testing server and it is working fine. When I go to the URL in the browser I get the "Symfony Project Created" page. I ran the check_configuration.php and everything checks out.
The problem I am having is: I have created my database and uploaded the table data. I have uploaded the files from my local machine to the server with FTP. When I try to access the module I created, it throws a 404 Error:
Not Found
The requested URL /mymodule was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
Here's some examples:
On my local machine using MAMP, I use the following URL that works fine:
http://localhost:8080/frontend_dev.php/mymodule
After I have uploaded everything, if I go to the testing server URL:
http://my.url.com:8090/
I get the "Project Success" page with the /sf images and styles.
BUT If I try
http://my.url.com:8090/mymodule
I get the 404 error as if the page does not exist, which makes me thik smfony does not know about the frontend module.
Any Help?
You'll need to do two things:
1) Ensure that mod_rewrite is enabled in Apache.
2) Double-check the .htaccess file in the document root to make sure it is pointing to your app.php. Something along the lines of:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]
</IfModule>
I used to have this problem too, please take a look at my configurations and try them out
inside my .htaccess:
Hi all, I have been having this problem too. And it seems that the "stock" .htaccess is the problem. I have solved this in my environment and here is my .htaccess with notes:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^app_dev.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L] ##### this is the part that you should tweak, have the .htaccess point the request to app_dev.php, since the routing.yml is empty initially
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .? - [L]
RewriteRule .? %{ENV:BASE}/app_dev.php [L] ##### this is the part that you should tweak, have the .htaccess point the request to app_dev.php, since the routing.yml is empty initially
</IfModule>
<IfModule !mod_rewrite.c>
<IfModule mod_alias.c>
# When mod_rewrite is not available, we instruct a temporary redirect of
# the startpage to the front controller explicitly so that the website
# and the generated links can still be used.
RedirectMatch 302 ^/$ /app.php/
# RedirectTemp cannot be used instead
</IfModule>
</IfModule>
inside my "symfony" entry in /etc/apache2/sites-available:
<VirtualHost 127.0.1.15>
ServerAdmin webmaster#localhost
ServerName symfony
DocumentRoot /var/www/Symfony/web
DirectoryIndex app.php
<Directory /var/www/Symfony/web>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Symfony uses the following typical .htaccess file:
Options +FollowSymLinks +ExecCGI
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
and I have this as my vhost:
<VirtualHost 127.0.0.1:80>
ServerName jobeet.loc
DocumentRoot "C:/wamp/www/jobeet/web"
DirectoryIndex index.php
<Directory "C:/wamp/www/jobeet/web">
AllowOverride All
Allow from All
</Directory>
Alias /sf "C:/wamp/lib/symfony-1.4.1/data/web/sf"
<Directory "C:/wamp/lib/symfony-1.4.1/data/web/sf">
AllowOverride All
Allow from All
</Directory>
The above works perfectly, but I want to know how to map and additional debugging url, http://jobeet.dev to automatically serve the frontend_dev.php file so I can use urls like:
http://jobeet.dev/jobs/...
instead of
http://jobeet.dev/frontend_dev.php/jobs/...
to map to the debug .php file in the framework.
I tried adding a duplicate of the vhost entry and simply changing the servername and directoryindex to
ServerName jobeet.dev
DirectoryIndex frontend_dev.php
but understandably this does not work, as I believe I would need to check the URL in the .htaccess to do this?
Can anyone offer some advice regarding this?
Thanks in advance!
:)
First add jobeet.dev as a ServerAlias in your current VirtualHost so it can share the same hosting configuration:
<VirtualHost 127.0.0.1:80>
ServerName jobeet.loc
ServerAlias jobeet.dev
DocumentRoot "C:/wamp/www/jobeet/web"
....
Don't forget to restart Apache when you're done.
Next, turn on no_script_name in your dev configuration in apps/frontend/config/settings.yml:
dev:
.settings:
no_script_name: true
Now your dev web controller (frontend_dev.php) won't show up in your auto-generated URLs (from link_to(), url_for(), etc).
Finally, set up a RewriteRule for your dev domain before your production controller comes in to play to route everything coming in at jobeet.dev to your dev web controller:
RewriteEngine on
...
...
RewriteCond %{HOST_NAME} ^jobeet\.dev$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ frontend_dev.php [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
That should do it.
I'd recommend you to map all needed hosts (jobeet.loc, jobeet.dev, etc) to SF_DIR/web, set index.php as dir-index (as you did) and in that file just run particular app with a particular env depending on $_SERVER['HTTP_HOST'].
Hope I described good to make an idea clear.