I have two Yiiframework applications with this structure:
.framework
.site
.site2
But, if I try to open the site: www.mysite.com/site2 I receive 404 error of Yii( exception.CHttpException.404) saying that he didn't find the Controller called: site2
I already added a virtualhost of site2 on my apache:
<Virtualhost *:80>
ServerName www.mysite.com/site2
ServerAlias www.mysite.com/site2
ServerAdmin www#localhost
DocumentRoot "/home/server/public_html/site2/"
<Directory "/home/server/public_html/site2/">
Order allow,deny
Allow from All
AllowOverride All
</Directory>
</VirtualHost>
My .htaccess that it's inside of "site folder" (I redirect to https://):
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
RewriteCond %{HTTPS} off
RewriteRule ^(.*) https://%{HTTP_HOST}/$1
I want that, when I open the site: www.mysite.com/site2 goes to my subdirectory /site2 and not /site. What I'm doing wrong?
Site 2 is not a site, but a subdirectory in the URL www.mysite.com/site2
The ServerName value is incorrect. You will have to another site name or a subdomain name
<Virtualhost *:80>
ServerName site2.mysite.com
ServerAdmin www#localhost
DocumentRoot "/home/server/public_html/site2/"
<Directory "/home/server/public_html/site2/">
Order allow,deny
Allow from All
AllowOverride All
</Directory>
</VirtualHost>
or
<Virtualhost *:80>
ServerName www.site2.com
ServerAdmin www#localhost
DocumentRoot "/home/server/public_html/site2/"
<Directory "/home/server/public_html/site2/">
Order allow,deny
Allow from All
AllowOverride All
</Directory>
</VirtualHost>
Related
This is my Virtual Host:
<VirtualHost *:8080>
ServerAdmin webmaster#dummy-host.localhost:8080
DocumentRoot "D:/test/testpage/"
ServerName testpage
ServerAlias testpage.localhost
ErrorLog "logs/testpage-error.log"
CustomLog "logs/testpage-access.log" common
</VirtualHost>
system/host
127.0.0.1 testpage.localhost
httpd.conf in xampp/apache/conf/
Listen 8080
ServerName localhost:8080
LoadModule rewrite_module modules/mod_rewrite.so
<Directory />
AllowOverride All
Require all granted
</Directory>
my .htaccess file inside testpage folder
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
and in my application/config/config.php
$config['base_url'] = 'http://testpage.localhost:8080';
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
the only issue am facing is that index.php, i can access my other pages but it have index.php between base_url() and view.
I suggest trying the following VirtualHost (vhost) directives.
It defines D:/test/testpage/testpage as the pubic root of the site. Both .htaccess and CodeIgniter's index.php should be in this directory.
I've removed the ServerAlias - you don't need it.
I've added explicit directives for the vhost directory
<VirtualHost *:8080>
ServerAdmin webmaster#dummy-host.localhost:8080
DocumentRoot D:/test/testpage
ServerName testpage
ErrorLog "logs/testpage-error.log"
CustomLog "logs/testpage-access.log" common
<Directory D:/test/testpage>
Options -Indexes +FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
system/host should be
127.0.0.1 testpage
Because you have named the virtual host "testpage" the following should work.
$config['base_url'] = 'http://testpage/';
I want to configure a Wordpress application with a simple php application. The directory structure of the application is as follow :
Root directory : /var/www/demoApp/
Wordpress directory : /var/www/demoApp/wordpress/
Here i want to access the wordpress application using route http://BASE_URL/wordpress. But i am not able to configure the htaccess file. All the php pages under /var/www/demoApp/ directory are working fine using url http://BASE_URL/. While wordpress files are not being loaded correctly.
Here is my Apache configuration block :
<VirtualHost *:80>
ServerName localhost
ServerAdmin webmaster#localhost
DocumentRoot /var/www/demoApp
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/demoApp>
Options FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
What should be the .htaccess file?
My configuration:
domain: test.localhost
wordpress url: test.localhost/wordpress
.htaccess in the wordpress folder:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wordpress/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wordpress/index.php [L]
</IfModule>
# END WordPress
Apache settings for the subdomain (Wamp server under windows)
<VirtualHost *:80>
DocumentRoot "e:\Sync\www\test"
ServerName localhost
ServerAlias test.localhost
<Directory "e:\Sync\www\test">
Options Indexes FollowSymLinks
AllowOverride all
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
Allow from ::1
</Directory>
</VirtualHost>
I had this issue while trying to modify a few absolute paths to relative paths. The problem was that I left an extra / at the start of the relative path.
Correct Code:
About
<!--The link goes to to http://BASE_URL/wordpress_subdirectory/about-->
Errorneous code:
/About
<!--This href is relative to the 'Root'. It goes to http://BASE_URL/about-->
I wanted to isntall laravel in a sub directory inside my dev machine http://dev-machine/applis/main/laravel
My default document root is F:/data/web
My .htaccess file is
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /applis/main/laravel
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
My httpd.conf file has below code
<VirtualHost *:80>
ServerName http://dev-machine/applis/main/laravel/public
DocumentRoot F:/data/web/applis/main/laravel/public
<Directory "applis/main/laravel/public">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
I have also tried the belwo virtual host config
<VirtualHost *:80>
ServerName http://dev-machine/applis/main/laravel/public
Alias /laravel applis/main/laravel/public
DocumentRoot F:/data/web/applis/main/laravel/public
<Directory "/applis/main/laravel/public">
AllowOverride all
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
But stil I am unable to access the app via
http://dev-machine/applis/main/laravel/public
I am getting he below error
Not Found
The requested URL /applis/main/laravel/public/ was not found on this server.
After adding the virtual host when it is not even loading the index.php file when I try loading it directly via http://dev-machine/applis/main/laravel/public/index.php
I have a Virtual Host in Apache
<VirtualHost *:8080>
ServerName example.eu
ServerAlias www.example.eu
ServerAlias www.somethingElseThanExample.net
DocumentRoot "/something"
<Directory "something">
Options ExecCGI FollowSymLinks
AllowOverride all
Allow from all
Order allow,deny
</Directory>
</VirtualHost>
I want to redirect
www.somethingElseThanExample.net to www.somethingElseThanExample.net/foo/
This has to work for homepage and for internal pages so that
www.somethingElseThanExample.net/bar/ to www.somethingElseThanExample.net/foo/bar/
Is it possible to do it with Apache mod_rewrite through my htaccess? How do I do this in each case?
What if i need to have this result ONLY for homepage?
Since you seem to have access to your VirtualHost, then you could add the following to your <Directory> section:
RewriteCond %{HTTP_HOST} =www.somethingElseThanExample.net [NC]
RewriteCond %{REQUEST_URI} !^/foo/
RewriteRule (.*) /foo/$1 [R=302,L]
I am trying to integrate my portal with my website.
My website :
http://example.com
and My portal :
http://portal.com
Now I want to see my portal from :
http://example.com/portal
Part of my core apache config file (sites-enabled/website):
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName example.com
DocumentRoot /home/example/WebSite2.0/WebContent
DirectoryIndex index.php index.html
<Directory /home/example/WebSite2.0/WebContent>
Options +IncludesNOEXEC
AllowOverride None
Order allow,deny
allow from all
XBitHack On
AddType text/html .html
AddHandler server-parsed .html
</Directory>
Alias /portal /home/example/portal/CodeIgniter_2.1.0
<Directory /home/example/portal/CodeIgniter_2.1.0>
DirectoryIndex "index.php"
allow from all
Options +Indexes
#Options FollowSymLinks MultiViews
Order allow,deny
RewriteEngine On
RewriteBase /portal
#RewriteRule ^test\.html$ test.php
RewriteCond $1 !^(index\.php|css|images|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
RewriteCond $1 ^(css|images|js)
RewriteRule ^(.*)$ $1
</Directory>
</VirtualHost>
As you see my portal functions on top of CodeIgniter; Hence -
RewriteCond $1 !^(index\.php|css|images|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
Part of my core apache config file (sites-enabled/portal) :
<VirtualHost *:443>
ServerAdmin webmaster#localhost
ServerName portal.com
ServerAlias www.portal.com
DocumentRoot /home/example/portal/CodeIgniter_2.1.0
DirectoryIndex "index.php"
SSLEngine On
SSLCertificateFile "ssl/portal.com.crt"
SSLCertificateKeyFile "ssl/portal.com.key"
<Directory /home/example/portal/CodeIgniter_2.1.0>
Options FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
Header unset Server
ServerSignature Off
</Directory>
</VirtualHost>
Now the real problem is when I open http://example.com/portal the browser is looking for the images in the DocumentRoot and not in Alias.
e.g. for image from portal,
<img src="/images/example.png" style="margin-left:30px;height:50px;">
apache error log says -
File does not exist: /home/example/WebSite2.0/WebContent/images/example.png
I would hate to make changes to my code. I just want to get this thing working from the apache config file itself. Please help me do this.
RewriteBase /portal require that the url should begin with /portal. So:
RewriteCond $1 !^(index\.php|css|images|robots\.txt)
will not be hit.
<img src="/images/example.png" style="margin-left:30px;height:50px;">
will try to search file from DocumentRoot.
update1
For there is RewriteBase /portal, example.com/portal/images will hit the Rewrite rule, but example.com/images will not, so:
<img src="/images/example.png" style="margin-left:30px;height:50px;">
should be:
<img src="/portal/images/example.png" style="margin-left:30px;height:50px;">
update2
It is the answer given by #Hussain Tamboli himself, with:
RewriteRule /(images|js|css)/(.+)\.(.+)$ /portal/$1/$2.$3 [PT].
/images/Invoice.png will rewrite to /portal/images/Invoice.png