I've VPS in OVH and i developped website with j2ee and i associate apache with tomcat using mod_jk.
when i enter url http://ip_of_vps/myapp, i enter to website.
until now it's ok
now i add rewrite for access to website using only ip_of_vps without context (myapp), for this i'm using Rewrite in apache2.config like this :
<virtualhost *:80>
RewriteEngine On
LogLevel alert rewrite:trace6
RewriteRule ^/$ http://ip_of_vps/myapp/ [P,L]
</virtualhost>
And i change All AllowOverride in directory from none to All
when i try to access to http://ip_of_vps, i've apache2 home page.
what i've forgot ?
I'm using ubuntu 14.04 server, apache2, tomcat7.
Off the top of my head, typically you would write
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
ReWriteRule your rule
</IfModule>
so, is mod_rewrite actually loaded?
do you need your RewriteBase to be /myapp/ ?
my suggestion would be to put a .htaccess in your html root directory
with a rule like
RewriteRule ^myapp/(.*)$ $1 [L]
this way you wont need mod_proxy at all
hope this helps
Related
I created Common Helper for Image Upload & Common Trait Function for get Images Full URL from Storage & I tested it in Laravel's default inbuilt server it's 1005 perfectly works.
but after Deployment I can't Display Images. it's show 404 error to me
I shared my Common function of Get Full URL path of Image from storage.
app/Traits>HasProfilePhoto.php file
public function getProfilePhotoUrlAttribute()
{
return $this->profile_photo_path
? Storage::disk($this->profilePhotoDisk())->url($this->profile_photo_path)
: \URL::to('/').'/adminLTE/dist/img/user-img.png';
}
above function will returns Image's Full URL Path Like."test.com/storage/users/user.png"
using Laravel's Default Inbuilt server it returns Full URL like this. http://localhost:8000/storage/users/user.png & using that path image display perfectly
but after the deployment in local Windows using XAMPP Server, it returns Full URL like this. http://localhost/ProjectFolderName/storage/users/user.png & it's show 404 Not Found
NOTE:- If I use FULL Url like this:- http://localhost/ProjectFolderName/public/storage/users/user.png then image displayed
Please Help me what's my mistake there?
*
**How I deployed my Laravel Project see below:- **
*
root/server.php file renamed with index.php
& root/public/.htaccess file copied at root directory
Rename the server.php file to index.php is not good practice for security reasons as well. So if you need to hide the public path from the URL then create a .htaccess at root level:
<ifmodule mod_rewrite.c>
<ifmodule mod_negotiation.c>
Options -MultiViews
</ifmodule>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ ^$1 [N]
RewriteCond %{REQUEST_URI} (\.\w+$) [NC]
RewriteRule ^(.*)$ public/$1
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ server.php
</ifmodule>
Updated by Harsh Patel:- 8th September 2021
Actually Problem is about defining Virtual Host in Server... I was defined DocumentRoot path & Directory path as like "C:/xampp/htdocs/projectFolderName/ this.
I was identified my mistake in deployment from here medium's Blog
but as per Laravel Documentation , we need to direct all requests to public/index.php in other words Laravel's Public Folder is an Our Server's Root (public_html) folder that's why I need to define DocumentRoot & Directory up to public folder like this C:/xampp/htdocs/projectFolderName/public
We need to define our Laravel Web in Apache Server's Virtual Host Config.
for XAMPP Server
step 1: open C:\xampp\apache\conf\extra path location in XAMPP Server
step 2: Open httpd-vhosts.conf File
step 3: define virtual host rule as like below
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
DocumentRoot "C:/xampp/htdocs/projectFolderName/public"
<Directory "C:/xampp/htdocs/projectFolderName/public">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
IF you faced any problem to define Virtual Host in XAMPP then you can see Full detailed answer about How to define Virtual Host in XAMPP
& If you Use WAMPP Server then you can see Full detailed answers about How to define Virtual Host in WAMPP
Maybe you just need to set your projects URL inside .env to start with http://
APP_URL=http://your-project-url
Without this, images will not have proper URL but when you copy image path and open it inside new tab, image will be available anyway.
I'm trying to move a working project from XAMPP to Laragon.
Everything is fine, but some directives I've put in my .htaccess don't work anymore: all modules seems to be enabled correctly.
What I'm trying to have working again is the versioning for my assets:
<IfModule mod_rewrite.c|rewrite_module>
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)\.(\d+)\.(css|js)$ $1.$3 [L]
</IfModule>
This is placed in the root of the project with Laravel, but moving it into the public folder does not change anything
In the Apache config I have the following correctly uncommented:
LoadModule rewrite_module modules/mod_rewrite.so
And this is the host configuration (untouched)
<VirtualHost *:80>
DocumentRoot "C:/laragon/www/projectski/public/"
ServerName projectski.localhost
ServerAlias *.projectski.localhost
<Directory "C:/laragon/www/projectski/public/">
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
As you can see it points to /public, but moving to the root (which I would like to, considering server configuration) will disable everything and turn the local site into a directory.
Please help me move to Laragon.
For those still looking for an answer, Laragon does not ignore .htaccess
The error was a simple syntax error in the IfModule
<IfModule mod_rewrite.c | rewrite_module>
# Logic
</IfModule>
Installed LAMP stack. Right now I've extracted codeigniter files to /var/www/ci
but while running on browser http://localhost/ci/ the welcome page doesn't display.
Finally found the answer. Have to enable the site.
In /etc/apache2/sites-available/000-default.conf file shud modified as follows:
<VirtualHost *:80>
DocumentRoot /var/www/
ServerAdmin webmaster#localhost
<Directory /var/www/ci/>
AllowOverride All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
And this worked for me! Thanks all.
If you are using ubuntu 14.04 the web server inside var/www/html, so move your folder into var/www/html/ci.
And open .htaccess file inside ci folder.paste the following code
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /ci/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
You can set the base url in /application/config/config.php on line 26.
$config['base_url'] = 'http://localhost/ci/';
If that doesn't solve the problem you have to post more informations.
Fresh codeigniter install?
No third party plugins?
No changes to routes? (in /application/config/routes.php)
No changes to the controller?
No changes to the view?
Do you get errors?
If not check if error reporting is on in the index.php (set it hard to development for testing)
Do you use Rewrite rules in an .htaccess in the /var/www/ci/ folder?
Do you autoload anything? libraries, models, languages, helpers ?
If you can't find anything, set this to 4:
$config['log_threshold'] = 4;
in /application/config/config.php on line 216.
The log file is written to /application/logs/.
Post that log, probably it helps.
I've done a 1st install of Symfony2,
php app/console --version
Symfony version 2.0.11 - app/dev/debug
I installed it under an existing DocumentRoot by configuring my apache2 server vhost
<VirtualHost 127.0.0.1:80>
...
DocumentRoot /srv/www/localhost_www
...
<Directory "/srv/www/localhost_www" >
AllowOverride none
Options -ExecCGI +FollowSymLinks +Includes +Indexes +MultiViews
Order Allow,Deny
Allow from All
</Directory>
...
Alias /TESTAPP "/srv/www/TESTAPP/web/"
<Directory "/srv/www/TESTAPP/web/">
Options All
AllowOverride All
Allow from All
</Directory>
Alias /TESTAPP.symfony "/srv/www/TESTAPP/"
<Directory "/srv/www/TESTAPP/">
Options All
AllowOverride All
Allow from All
</Directory>
...
After an OK install, and successfully following "The Book" to build the demo "Hello" app, if I nav in a browser to any/all of,
dev:
http://localhost/TESTAPP.symfony/web/app_dev.php/hello/ME
http://localhost/TESTAPP/app_dev.php/hello/ME
prod:
http://localhost/TESTAPP.symfony/web/app.php/hello/ME
http://localhost/TESTAPP/app.php/hello/ME
I see the expected,
"Hello ME!"
I want to rewrite only the production URLs, hiding "app.php" so that the following set of URLs work in the nav bar of a browser for my Symfony2 app:
dev:
http://localhost/TESTAPP.symfony/web/app_dev.php/hello/ME
http://localhost/TESTAPP/app_dev.php/hello/ME
prod:
!! http://localhost/TESTAPP.symfony/web/hello/ME
!! http://localhost/TESTAPP/hello/ME
Iiuc, the default web/.htaccess
cat web/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]
</IfModule>
needs to change.
I've dug around in the docs and on the web, tried vdiffferent recommendations for modding the RewriteRule, adding 'RedirectMatch permanent', etc., and I'm not managing to get a simple
http://localhost/TESTAPP/hello/ME
to ever work. I always seem to need to add the "/app.php/".
What are the specific changes I'd need to make in order to get this to work?
Thanks.
#chasen
is mod_rewrite enabled for apache?
yes
if you have your .htaccess file in your web directory
i do
and you host file pointing to the web folder the
it is, as above,
Alias /TESTAPP "/srv/www/TESTAPP/web/"
<Directory "/srv/www/TESTAPP/web/">
app.php should not be needed.
that's my problem. without it, it's not working for me.
Specifically,
https://localhost/TESTAPP/app.php/hello/ME
returns:
"Hello Me!"
but
https://localhost/TESTAPP/hello/ME
returns
Object not found!
The requested URL was not found on this server.
If you entered the URL manually please check your
spelling and try again.
If you think this is a server error, please contact
the webmaster.
Error 404
i know that its a silly question but is mod_rewrite enabled for apache?
if you have your .htaccess file in your web directory and you host file pointing to the web folder the app.php should not be needed.
if you are running ubuntu or a similar distro you can do:
sudo a2enmod rewrite
sudo service apache2 reload
sudo service apache2 restart
That should enable the mod, and reload apache.
EDIT:
That response you are getting back is it in a symfony page? if it is its likely that your prod cache needs to be cleared, from the root directory for the application use the symfony console to clear the cache:
php app/console cache:clear --env="prod"
EDIT:
If neither of those have worked you may try adding a RewriteBase to the htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /TESTAPP
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]
</IfModule>
In my case I need to modify the line containing AllowOverride None to read AllowOverride All. This tells Apache that it's okay to allow .htaccess files to over-ride previous directives. You must reload Apache before this change will have an effect (https://help.ubuntu.com/community/EnablingUseOfApacheHtaccessFiles):
Do this: - go to "/etc/apache2" modify file "apache2.conf" section:
<Directory /var/www/>
Options FollowSymLinks
AllowOverride All
Require all granted
restart server: /etc/apache2# service apache2 restart
it should work. If it does not work, still you have done 1 step right to insure .htaccess is allowed to override. There are many other reasons can be fixed with the above instruction.
Adding the RewriteBase rule with the name of the folder in which the project is held to the .htaccess file does it's job! Thanks!
RewriteBase /project_name
I need to make a change to my Apache web server to redirect requests for the home page from iPhone browsers to a different page. I've edited the /etc/httpd/conf/httpd.conf file and added the following:
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} .*iPhone.*
RewriteRule ^/$ /iphone/index.html [L]
After making the change, I restarted httpd, but the redirect doesn't work.
Am I missing something? Do the edits need to be made to a specific location in the httpd.conf file?
Other info: Server is vps hosted by Lunarpages running CentOS 5.5 and Apache 2.2.3.
For me, I use like below
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} .*iPhone.*
RewriteRule ^[\./]$ <MyDomain>/iphone/index.html [L]