簡體   English   中英

自定義路由與htaccess php

[英]Custom route with htaccess php

與標題相同,我希望看起來像這樣:

.htaccess文件:

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule / index.php?r=site&action=index
RewriteRule ^user/[0-9]+$ index.php?r=user&action=profile&user_id=$1

但它不起作用,例如:

網址:' http://mysite.domain/ '

$route = filter_input(INPUT_GET, 'r'); // $route = null;

有人可以幫幫我嗎?

/請求時沒有斜杠。 處理htaccess文件中的規則時,將從URI中刪除前導斜杠。 嘗試:

RewriteEngine On
RewriteBase /

RewriteCond %{QUERY_STRING} ^$
RewriteRule ^(?:index\.php)$ index.php?r=site&action=index [L,QSA]
RewriteRule ^user/[0-9]+$ index.php?r=user&action=profile&user_id=$1 [L,QSA]

暫無
暫無

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

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