简体   繁体   English

htaccess重写网址,其中$ _GET为空

[英]Htaccess rewriting url with a $_GET empty

I have a problem, so my url will be like this : 我有问题,因此我的网址将如下所示:

www.site.fr/dashboard/posts/ www.site.fr/dashboard/posts/

and for some widget on the posts page that will be like this 以及帖子页面上的一些小部件

www.site.fr/dashboard/posts/add or www.site.fr/dashboard/posts/add
www.site.fr/dashboard/posts/remove/id(1,2...) www.site.fr/dashboard/posts/remove/id(1,2 ...)

But the real link will be 但是真正的联系将是

www.site.fr/dashboard/posts.php?action=add www.site.fr/dashboard/posts.php?action=add
www.site.fr/dashboard/posts.php?action=remove&id=(1,2...) www.site.fr/dashboard/posts.php?action=remove&id=(1,2 ...)

For now i use that .htaccess : 现在我使用那个.htaccess:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)/([^\.]+) $1.php?action=$2 [NC,L]

But with this htaccess , that make just delete the ".php" and if the $_GET["action"] is empty, that doesn't work , that make an error. 但是使用htaccess时,只需删除“ .php”,如果$ _GET [“ action”]为空,则不起作用,这将导致错误。

If $_GET["action"] is empty , logically that say action="index" but I don't want to show in the url /index/ . 如果$_GET["action"] ,则逻辑上说是action="index"但我不想显示在url / index /中 And for the ID, if $_GET["action"] is equal to "remove" , I can get the $_GET["id"] else care of the id . 对于ID,如果$_GET["action"]等于"remove" ,则可以得到$_GET["id"]否则需要id

Thanks a lot, sorry for my bad english. 非常感谢,抱歉我的英语不好。 I hope you'll understand what i means. 希望您能理解我的意思。

Maybe this would do 也许这样做

RewriteCond %{QUERY_STRING} ^$
RewriteRule ^/$ /index.php [L]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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