2016-06-27 35 views
0

我已按照以下步驟從url中刪除index.php。我正在laravel 5上工作,並且我已經跟着insrtuection刪除了index.php和url ..但是我無法訪問我的views文件夾和使用url的頁面。只有像www.art.local這樣的主鏈接正在工作www.art.local/index/register這不起作用。 請幫助無法從URL訪問laravel 5中的視圖

 Renaming the server.php to index.php (no modifications) 
     Copy the .htaccess from public 
     Changing .htaccess it a bit as follows for statics: 

     RewriteEngine On 

     RewriteCond %{REQUEST_FILENAME} !-d 
     RewriteRule ^(.*)/$ /$1 [L,R=301] 

     RewriteCond %{REQUEST_URI} !  (\.css|\.js|\.png|\.jpg|\.gif|robots\.txt)$ [NC] 
     RewriteCond %{REQUEST_FILENAME} !-d 
     RewriteCond %{REQUEST_FILENAME} !-f 
     RewriteRule^index.php [L] 

     RewriteCond %{REQUEST_FILENAME} !-d 
     RewriteCond %{REQUEST_FILENAME} !-f 
     RewriteCond %{REQUEST_URI} !^/public/ 
     RewriteRule ^(css|js|images)/(.*)$ public/$1/$2 [L,NC] 
+0

後,我已經使用這個代碼: – yogeshwari

+0

我改變/Illuminate/Foundation/helpers.php/asset()函數如下: 功能的資產($路徑,$ secure = null) { return app('url') - > asset(「public /".$ path,$ secure); } – yogeshwari

回答

0

在Laravel 5,默認情況下,你並不需要在您的網址index。例如,讓我們說我們有這個路線:

Route::get('register', function() { 
    return 'Hello world'; 
} 

所以,如果你試圖去localhost/register,你會得到的Hello World輸出。


更新1:

IIR,如果你使用像 「WampServer」 服務運行服務器,你應該能夠在Apache module_rewrite,然後重新啓動它。欲瞭解更多informatiom,請參閱本答案 - https://askubuntu.com/questions/48362/how-to-enable-mod-rewrite-in-apache

+0

仍然不工作:( – yogeshwari

+0

您是否恢復您的更改?請提供您的routes.php文件。 –

+0

我正在使用LAMP ... – yogeshwari

0

從公衆移動網站的主要網址在Windows下你應該做一個vitual host.to做到這一點首先打開

1.Open的XAMPP控制面板應用程序,並停止Apache的。請注意,後期的Windows機器可能會將其作爲服務運行,因此請檢查Apache模塊左側的框。

2.導航到C:/ xampp/apache/conf/extra或XAMPP文件所在的任何位置。

3.用文本編輯器打開名爲httpd-vhosts.conf的文件。

4.第19行找到#NameVirtualHost *:80並取消註釋或刪除散列。

在文件的最底部粘貼以下代碼:

<VirtualHost *> 
    ServerAdmin [email protected] 
    DocumentRoot "C:/xampp/htdocs" # change this line with your htdocs folder 
    ServerName localhost 
    ServerAlias localhost 
    <Directory "C:/xampp/htdocs"> 
     Options Indexes FollowSymLinks Includes ExecCGI 
     Order allow,deny 
     Allow from all 
    </Directory> 
</VirtualHost> 
  • 現在您可以複製和粘貼代碼上面的下方添加您的虛擬主機目錄。比如我正在一個叫食堂引擎網站,所以下面的代碼片段可以讓我與子域上我的本地安裝工作:

    <VirtualHost eateryengine.dev> 
    ServerAdmin [email protected] 
    DocumentRoot "C:/xampp/htdocs/laravel-projcet/public"#path to your project #in laravel project be sure to set path to public folder 
    ServerName eateryengine.dev 
    ServerAlias eateryengine.dev 
    <Directory "C:/xampp/htdocs/eateryengine"> 
        Order allow,deny 
        Allow from all 
    </Directory> 
    </VirtualHost> 
    

    7.Next頭部到您的Windows主機文件編輯您的主機。該文件將位於C:/Windows/System32/drivers/etc/hosts,其中主機是該文件。用記事本打開它。

  • 查找
  • localhost name resolution is handled within DNS itself. 127.0.0.1 localhost

  • 這條線的底部添加您的項目名稱(這是您的域的DNS服務器地址)
  • 127.0.0.1 localhost 127.0.0.1 eateryengine.dev #change to match your Virtual Host. 127.0.0.1 demo.eateryengine.dev #manually add new sub-domains.

    重新啓動Apache並測試所有內容。

    現在你可以無需輸入網址本地主機或公衆只要輸入您擁有註冊在的httpd-vhosts.conf文件

    在Windows中設置虛擬主機的原創文章可以在這裏找到http://austin.passy.co/2012/setting-up-virtual-hosts-wordpress-multisite-with-xampp-on-windows-7/域名訪問你的網站

    感謝陽光,但已經創建了虛擬主機..並在Linux中工作...路線:: get('/','UserController @ index');路線::得到( '/用戶', 'UserController的@我的賬戶');

    www.loveart.dev/然後fisrt正在工作。 www.loveart.dev/user第二不工作

    +0

    是我已經做到了,第一頁正在打開...但如果我必須訪問... http://www.weloveart.local/user/register這和路線文件路線::得到('用戶/註冊','控制器@註冊'); 路線::資源('用戶','控制器');這個我可以得到..如果你想訪問...請求幫助 – yogeshwari

    +0

    ... weloveart.local/user/register url並且已經聲明'/ user' url的資源,然後訪問'/ user.register'頁面手動註冊,如'Route :: get('user/register','Controller @ register');'有關路由的更多信息,請參見其[Documentation](https://laravel.com/ docs/4.2/controllers#restful-resource-controllers) –

    +0

    if you think taht route will effect a移動index.php文件然後你錯了。路線將像移動文件之前一樣運行。 –