i hope you can help me out as been scratching my head for ages..
I have the laravel 4 installed in a folder called 'myapp' www.example.com/myapp/
I'm calling this but i'm getting app undefined..
Route::get('login', function(){
//do something
});
The only way i can get it to work is this way, but it messes everything up all the styles etc..
Route::get('/myapp/login', function(){
//do something
});
And this is my current .htaccess file
<IfModule mod_rewrite.c>
RewriteEngine On
Options -MultiViews
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
Does anyone know how to get it to work just for the myapp folder?
Thanks in advance.
I've now figured this out.
I needed to change the .htaccess file from this
RewriteRule ^ index.php [L]
to this
RewriteRule ^ /myapp/index.php [L]
I think your web server might be misconfigured. A correct web server configuration usually requires no changes to .htaccess.
Normally, using Laravel, you should have a DocumentRoot directive that points the web server to the public directory of your Laravel installation.
Exactly how you do that varies a little among operating systems. On my system, which is a development system running Ubuntu Linux, and which hosts multiple Laravel projects, I use multiple virtual servers. Ubuntu's configurations for these virtual servers are stored in /etc/apache2/sites-enabled. The configuration file for my calendar project (locally, calendar.dev) looks like this.
$ cat /etc/apache2/sites-enabled/calendar.dev
<VirtualHost *:80>
ServerName calendar.dev
ServerAlias calendar.dev *.calendar.dev
DocumentRoot "/var/www/calendar/public"
HostNameLookups double
</VirtualHost>%
If you're using "myapp" in place of the default "public" folder, then your DocumentRoot directive should point to "myapp" instead of "public".
If you're using "myapp" in place of the default "app" directory, you need to back up and rethink this. The "app" directory shouldn't be accessible to web users.
I agree completely with Mike Sherrill. Laravel ships with .htaccess config file that works "out of the box". There was some problems with older Laravel versions, but with L4 no. If you plan to add new virtual host don't forget to register one in /etc/hosts file. So check your server configuration.
Related
first of all, I'm sorry for this umpteenth topic about this kind of problem.
I've tried to adapt other topics to my problem for months without being able to figure out how to do. That's why I'm writing today, it's really bugging me and as of today, I can only successfully do URL rewriting on remote but always coding in production remote folder isn't reliable solution.
This is what my file tree look like :
Firstly, I'd like to be redirected from the root of this 'template1' project to the root of the 'public' subfolder ; and secondly, I'd like to rewrite URLs so this kind of URL :
template1/index.php?route=qwertyuiop
turns into that :
template1/qwertyuiop
Both these things I want work but only on my remote folder on Ionos and I had to do weird things. For example for the redirection, I'm directly linking domain to subfolder and for URL rewriting I do :
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(\.png|\.jpg|\.gif|\.jpeg|\.zip|\.pdf|\.css|\.svg|\.js)$
RewriteRule ^(.*)$ /index.php?route=$1 [L,QSA]
Anyways, this works fine on remote folders and when I do PHP header("location:/azertyuiop") it works fine but in localhost it tries to search at the root of WAMPserver and I don't know how to proceed to fix it while keeping same code for both local and remote.
If any of you could help me figure out how to deal with this problem, it would be really appreciated as reading topics and putting whatever I can in my .htaccess doesn't work on localhost.
Ok, sooo thanks #MrWhite for basically telling me about VirtualHost. I never saw about it in any topics so I was searching maybe in the wrong direction.
Everything is working fine, now. So in case in the future someone gets through it, I will explain what I did to make it work in localhost. What I will tell is translated from a website I've found in my native language ( How to configure VirtualHost (French) ).
STEP 1 : edit Apache's config in Wamp
In the 'httpd-vhosts.conf' file located in 'C:/wamp64/bin/apache/apache2.4.46/conf/extra/httpd-vhosts.conf' (in my case), I had to add these virtual host lines :
<VirtualHost *:80>
ServerAdmin webmaster#dummy-host.localhost
DocumentRoot "${INSTALL_DIR}/www/projets/projets_persos/tests/template1/public"
ServerName template1.local
ServerAlias template1.local
ErrorLog "logs/template1.local-error.log"
CustomLog "logs/template1.local-access.log" common
</VirtualHost>
Then I had to modify Apache's main config file called 'httpd.conf' located in 'C:/wamp/bin/apache/apache2.4.46/conf/httpd.conf' (in my case) and uncomment the following line :
#Include conf/extra/httpd-vhosts.conf (in my case, it was already uncommented)
After that, the website says to restart Wamp's services before step 2, which I did after step 2 below and it stills work without any trouble. So anyway, I guess it will be same for you, do it now or after step 2.
STEP 2 : edit Windows' hosts file
At bottom of the 'hosts' file located in 'C:/Windows/System32/drivers/etc/hosts' I added the following line at bottom of the file to override the previous rule :
127.0.0.1 template1.local
Aaand, that's all.
=-=-=-=-=
As a proof it's working well, here's a screenshot of my project :
Here you can see on the picture I exploded my route in an array. I do this for personal purposes, to be able to route according to whatever bit of string I want. If you want to get rid of the 'public' value in the route, just type $_GET['route'] = str_replace('public/', '', $_GET['route']); before putting each of its fields in the array. Then, it will look like this :
Also, of course, I used .htaccess to be able to do URL Rewriting, here's my .htaccess file :
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(\.png|\.jpg|\.gif|\.jpeg|\.zip|\.pdf|\.css|\.svg|\.js)$
RewriteRule ^(.*)$ /index.php?route=$1 [L,QSA]
It's a bit off topic but in case you'd need to know, the RewriteCond lines allow to type in the true URL of assets that have these extensions and it won't rewrite as they are true URLs.
=-=-=-=-=
Anyway, this is the end of my solution, thanks again for helping me and all's well that ends well. The End.
I have a WordPress website (mywebsite.com) running on a shared hosting server. Alongside, I made a node.js app running in the backend on port 3000, which has been programmed to have different API endpoints.
I would like to have the endpoints to be in the same domain as the website in specific URLs.
The main endpoint, which has been declared in the node.js selector environment, works just fine. Let's call it mywebsite.com/myapp.
The other endpoints (which have been declared in the express routes) work correctly outside the website environment but are instead caught by apache/wordpress if I try to access them on the same domain even as sub-uri.
For example, if I try to access mywebsite.com/secondendpoint or mywebsite.com/myapp/thirdendpoint, the request gets caught by Wordpress which loads the 404 page.
Now, I understand that I have to instruct the apache server to redirect the requests to the above mentioned URL to the node.js app.
As long as I don't have access to the apache server, the only choice I have to tweak the .htaccess files.
When I created the node.js app, the virtual environment has been automatically set through a .htaccess file in its own subfolder in my website public folder, where my whole website is: /public_html/myapp . It uses Phusion Passenger to handle the virtual environment the app is running in.
# DO NOT REMOVE. CLOUDLINUX PASSENGER CONFIGURATION BEGIN
PassengerAppRoot "/home/user/apps/myapp"
PassengerBaseURI "/myapp"
PassengerNodejs "/home/user/nodevenv/apps/myapp/12/bin/node"
PassengerAppType node
PassengerStartupFile app.js
PassengerAppLogFile "/home/user/logs/myapp.log"
# DO NOT REMOVE. CLOUDLINUX PASSENGER CONFIGURATION END
The above code works just fine. I tried to add an Alias as suggested in some tutorial:
# DO NOT REMOVE OR MODIFY. CLOUDLINUX ENV VARS CONFIGURATION BEGIN
<IfModule Litespeed>
SetEnv Alias /secondendpoint /apps/secondendpoint
</IfModule>
# DO NOT REMOVE OR MODIFY. CLOUDLINUX ENV VARS CONFIGURATION END
In the root of /public_html/ I have the following .htaccess file
# BEGIN WordPress
# The directives (lines) between "BEGIN WordPress" and "END WordPress" are
# dynamically generated, and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^/secondendpoint/(.*)?$ http://127.0.0.1:3000/secondendpoint/$1 [P,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
No matter what I try, when I try to access mywebsite.com/secondendpoint, I always get the Wordpress 404 message.
What am I doing wrong?
I even tried to create a subfolder in /public_html/secondendpoint which actually does proxy the traffic, but I feel like this is not the right way to do it.
So, after a week of attempts, I found out that the syntax of the RewriteRule was indeed wrong for what I was trying to achieve.
RewriteRule ^/secondendpoint/(.*)?$ http://127.0.0.1:3000/secondendpoint/$1 [P,L]
The correct syntax is
RewriteRule ^secondendpoint(.*)$ http://127.0.0.1:3000/secondendpoint/$1 [P,L]
As shown in the comment of the .htaccess file "should only be modified via WordPress filters".
In fact is does automatically overwrites the rules I wrote every time it updates.
The right way to do it would be tweaking the internal WordPress WP_Rewrite
which I'm still trying to understand.
My best attempt has been adding to functions.php of my theme these lines:
function wpd_wtf_rewrite_rule() {
add_rewrite_rule(
'secondendpoint(.*)$',
'http://127.0.0.1:3000/secondendpoint$1',
'top'
);
}
add_action( 'init', 'wpd_wtf_rewrite_rule' );
These lines are being translated in
RewriteRule ^secondendpoint(.*)$ /http://127.0.0.1:3000/secondendpoint$1 [QSA,L]
and updated into the .htaccess file.
The slash in front of the target is an issue I don't know how to fix.
However, the generated .htaccess string does not proxy the requests resulting in errors from the API.
I have 3 php apps on one server. I cant modify any apache files. Haw can I set .htaccess to remove web/ folder from url?
192.168.45.54/app1/
192.168.45.54/app2/
192.168.45.54/app3/web - I want to change it to 192.168.45.54/app3/
On adress 192.168.45.54/app3/web/ everythink is working fine. But haw can I remove web/ from url?
I created .htaccess files:
RewriteEngine On
RewriteBase /app3
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ web/$1 [QSA,L]
But when I go to 192.168.45.54/app3/ in symfony log files I have fallowing error:
No route found for "GET /app3/"
I use Symfony in 3.4 version. I think that problem is in .htaccess located in /web directory... Haw to configure .htaccess corectly?
I can't create virtual host becouse I haven't access to the server...
You need to make the web/ directory the document root of your website. If you have direct access to the webserver’s virtual host configuration, change the document root to the following line and restart Apache:
DocumentRoot /path/to/symfony/web/
If you can’t modify the virtual host file directly, your hosting provider will usually give you the possibility to modify the document root through some kind of online tool.
I'm scratching my head for almost two days now, thought some expert advice can help me here.
I got a CodeIgniter application I need to maintain (version 2.X), and this is my first experience with it. The structure of the application is:
myApp
application
cache
certs
config
controllers
...
modules
moduleA
controllers
models
views
moduleB
controllers
models
views
...
third_party
views
cgi-bin
...
system
themes
uploads
I installed WAMP, and throw the entire myApp under c:\wamp\www. Another steps I did:
1) Changed the 'listen' port of the Apache since I also run IIS on my machine.
2) Enabled the Apache rewrite module.
3) Set the 'all' and 'all granted' in the <Directory .../> section:
<Directory "c:/wamp/www/">
Options Indexes FollowSymLinks
AllowOverride all
Require all granted
</Directory>
4) Set correctly the database name in the 'database.php' config.
5) Verified .htaccess file is located under myApp folder, and the content of the .htaccess is this:
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
6) In 'routes.config' the default controller is: $route['default_controller'] = "login";
With these steps I was able to host this application locally and work for a while. But, I had to change my Windows user password, and after rebooting my computer I receive 404 errors all of a sudden.
I am able to browse to the 'login' page via http://localhost:port/myApp/index.php (or just http://localhost:port/myApp), but from there I receive only 404 error messages. I can browse with the full url though:
http://localhost:port/mpApp/index.php/login/forgotpassword - Accessible
http://localhost:port/myApp/login/forgotpassword - 404 error
Now, I am not sure whether it's related to my Windows user password change, but this issue became a voodoo, since I swear I could work and browse locally to all pages. I also reinstalled WAMP twice and repeated
the process above just to make sure I'm doing things right.
Can anyone think of something I am missing here?
Found the issue, at least the one worked for me:
In config.php (under ...myApp\application\config) I changed the value of $config['uri_protocol'] from 'AUTO' to 'PATH_INFO'.
I have my .htaccess file working in localhost. But its not working if i upload it in server. It throws me 404 error.
I am using Parallel Plesk 11.0.9 and i can't find conf file for the same on that. If anyone has any idea how to fix it or any workaround for url rewriting would be great help.
Anyway here's the code in htaccess:
RewriteEngine on
RewriteRule ^store/living/Hutches-Armoires-Side-tables-Coffee-tables-Entertainment-centers? store.php?store=Living
RewriteRule ^store/dining/sideboards-buffets-chairs-benches-Dining-table$ store.php?store=Dining
RewriteRule ^store/working/Bookshelves-Study-tables$ store.php?store=Working
RewriteRule ^store/accessories/Boxes-Photo-Frames-Mirror-Frames-Block-Stamps-and-Book-stands$ store.php?store=Accessories
RewriteRule ^store/hallway/Console-tables-Armoires$ store.php?store=Hallway
RewriteRule ^store/sleeping/Bed-Frames-Night-Stands-Dressers-Mirror-framesBed-Linens-Canopies-Curtains$ store.php?store=Sleeping
You may need to wrap your rewrite rules with:
<IfModule mod_rewrite.c>
...
</IfModule>
...probably a good idea anyway.
Or you could try putting your rules into a vhost.conf file in the conf directory immediately below the location of your httpdocs directory. For example on a Centos machine the web root might be
/var/www/vhosts/domain.com/httpdocs
and you should have a:
/var/www/vhosts/domain.com/conf
directory, this will contain a set of pregenerated Apache config files that Plesk creates. If there isn't already create a vhost.conf and add your rules between a set of
<Directory /var/www/vhosts/domain.com/httpdocs/ >
... your rules ...
</Directory>
Once you've created the vhost.conf file you will need to tell plesk about it with
/usr/local/psa/admin/sbin/httpdmng --reconfigure-domain domain.com
If you still can't get it to work you can add a log for mod_rewrite, see this relevant SO answer for details
Is your Plesk running IIS and supporting PHP via FastCGI or ISAPI? If that is the case, check whether URL Rewrite is installed and follow this guide to translate htaccess (for apache) into web.config (for IIS)