CodeIgniter Route works over CIFS mount but not with local files - php

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';

Related

Local Laravel error 404 with duplicated URL redirection

Currently trying to set up a Laravel project on my local PC.I added the hostname 127.0.0.1 localhost-smt to the Windows hostfile and edited my Apache httpd-vhost.conf:
<VirtualHost *:80>
ServerName localhost
DocumentRoot "C:/xampp/htdocs/project1"
<Directory "C:/xampp/htdocs/project1/">
DirectoryIndex index.php
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName localhost-smt
DocumentRoot "C:/xampp/htdocs/project1/smt/public"
ErrorLog "logs/testseite-error.log"
CustomLog "logs/testseite-access.log" common
<Directory "C:/xampp/htdocs/project1/smt/">
AllowOverride All
Allow from All
</Directory>
</VirtualHost>
My Apache httpd.conf
DocumentRoot "C:/xampp/htdocs"
<Directory "C:/xampp/htdocs">
Each time I connect to localhost-smt/home I am receiving a double URL like http://localhost-smt/127.0.0.1/home. Further more if I navigate from localhost to the public folder and add /home i receive the following URL http://localhost/smt/public/127.0.0.1/smt/public/home.
I tried a lot of different solutions, but none of them worked so far. I would appreciate if someone could help me solve this riddle.
I'm not sure how to do this using .conf files but the way I used to achieve this when I used Xampp was as follows, doing it this way will obviously mean undoing anything you have done to the default behaviour of Xampp relating to the .conf files you have edited.
Add the name resolution to your hosts file
127.0.0.1 dev.projectName
Add the following .htaccess file into the root of your projects directory (typically "C:/xampp/htdocs")
RewriteEngine On
RewriteCond %{HTTP_HOST} !^dev.projectName$
RewriteRule .? - [S=1]
RewriteRule ^(.*)$ projectName/$1 [L]
add the following .htaccess file to the root of your project (typically "C:/xampp/htdocs/projectName")
RewriteEngine On
RewriteBase /dev.projectName/
RewriteCond %{THE_REQUEST} /public/([^\s?]*) [NC]
RewriteRule ^ %1 [L,NE,R=302]
RewriteRule ^((?!public/).*)$ public/$1 [L,NC]
Add the following .htaccess file into your public directory (typically "C:/xampp/htdocs/projectName/public")
RewriteEngine On
RewriteBase /dev.projectName/public/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [QSA,L]
this can be viewed by going to http:\\dev.projectName
I know it is a long-winded way of doing it but it was the only solution I could find at the time and it worked for me.
It does become a ball-ache having to do this every time you create a new project which is one of the reasons I switched to docker which in my opinion is a much better solution anyway,

Zf2 change startup location

I have zf2 on my web server and I cannot change the startup location in Apache. I copied .htaccess to public_html with changed path on /public/index.php but I have the problems with CSS styles and js. Can I make it in .htaccess without errors?
.htaccess:
RewriteEngine On
# The following rule tells Apache that if the requested filename
# exists, simply serve it.
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [L]
# The following rewrites all other queries to index.php. The
# condition ensures that if you are using Apache aliases to do
# mass virtual hosting or installed the project in a subdirectory,
# the base path will be prepended to allow proper resolution of
# the index.php file; it will work in non-aliased environments
# as well, providing a safe, one-size fits all solution.
RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteRule ^(.*)$ %{ENV:BASE}/public/index.php [L]
If you are in a local development environment you don't need change the .htaccess at all, if you create a virtual host as #bartek_zet said.
So use the default .htaccess file, and create a virtual host like that:
# usually stored in /etc/apache/site-enabled/my-application.conf
<VirtualHost *:80>
ServerName zf2-tutorial.localhost
DocumentRoot /path/to/zf2-tutorial/public
SetEnv APPLICATION_ENV "development"
<Directory /path/to/zf2-tutorial/public>
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
More information in ZF2 documentation.

which one is better to run laravel?

I have installed laravel in my cpanel and localhost, but i found two way to execute/run laravel.
access the
/public/
use
php artisan serve
if i run in my notebook/localhost i can use php artisan serve and it done well like routing and database, but in my cpanel i cant use the second way, so i must use first way, but it not done well like routing and etc.
So which one is better and how to make the first way run well?
Normally, you would use
php artisan serve
on your development environment only.
On production servers, you will add a <VirtualHost> or an Alias drective in your Apache configuration.
<VirtualHost *:80>
ServerAdmin admin#localhost
DocumentRoot /path/to/your/laravel/public
ServerName your.domain.com
<Directory /path/to/your/laravel/public>
AllowOverride None
Order allow,deny
Allow from All
Options FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</Directory>
</VirtualHost>
With this type of configuration, you can access your Laravel site as:
http://your.domain.com/
When using an Alias, your Apache configuration will be something like this:
Alias /any/path/you/want /path/to/your/laravel/public
<Directory "/path/to/your/laravel/public">
Order allow,deny
Allow from All
Options +FollowSymLinks
RewriteEngine On
RewriteBase /any/path/you/want
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</Directory>
With this configuration, you will access your laravel as: http://your.domain.com/any/path/you/want
On some web hosting providers, you don't have access to the Apache configuration,
in which case, you will have to put your configuration in an .htaccess file inside your public directory.
Laravel has a default .htaccess file inside the public directory that contains this:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
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]
</IfModule>
You will have to check if your hosting allows .htaccess

Problems with codeigniter on ubuntu

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

How do I map different server names to differrent DirectoryIndex in PHP Symfony?

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.

Categories