簡體   English   中英

laravel 4重寫分頁URL

[英]laravel 4 rewrite url for pagination

我使用Laravel分頁,但網址是這樣的:

http://mydomain.com/?page=2

我更喜歡這樣的網址:

http://mydomain.com/page/2

我有htaccess:

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    # Redirect Trailing Slashes...
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]

</IfModule>

我嘗試一下:

RewriteRule ^/([0-9])$ index.php?page=$1

但這不起作用...知道嗎? 可以使用.htaccess文件以外的其他文件嗎?

據我了解,Laravel的默認分頁系統不支持您要查找的那種路由。

因為您的應用程序中每個頁面的路由看起來都非常不同,所以很難附帶.htaccess中的所有RewriteRule,它們可以以Laravel可以理解的格式正確重寫URL,同時也不會弄亂其他URL參數和路徑。


對於您的特定示例, 但這僅適用於您的特定示例,除此之外 ,您可以嘗試以下操作:

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    # Redirect Trailing Slashes...
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    #Handle pagination for urls like http://mydomain.com/page/2
    RewriteRule ^page/([0-9]+)$ index.php?page=$1

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]

</IfModule>

同樣,這不是一般的解決方案,僅適用於http://mydomain.com/page/2之類的鏈接(不適用於http://mydomain.com/users/page/2之類的鏈接)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM