简体   繁体   中英

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.

  1. Add the name resolution to your hosts file

127.0.0.1 dev.projectName

  1. 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]
  1. 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]
  1. 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]
  1. 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,

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM