简体   繁体   English

PHP 中查询字符串的 HTACCESS 重写规则

[英]HTACCESS Rewrite Rule for Query String in PHP

I have my URL https://example.com/?hfgshdsds .我有我的 URL https://example.com/?hfgshdsds

I need to rewrite a rule to makes that even If I removed the question mark, the link will works as same as before, so my url need to be https://example.com/hfgshdsds .我需要重写一个规则,即使我删除了问号,链接也会像以前一样工作,所以我的 url 需要是https://example.com/hfgshdsds

For the moment on my .htaccess file I have only the rule that open the php without extension.php.目前在我的 .htaccess 文件中,我只有打开不带扩展名的 php 的规则。php。

RewriteEngine On
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule !.*\.php$ %{REQUEST_FILENAME}.php [QSA,L]

Thank you!谢谢!

With your shown samples, please try following htaccess Rules file.使用您显示的示例,请尝试遵循 htaccess 规则文件。 Please make sure to clear your browser cache before testing your URLs.请确保在测试您的 URL 之前清除您的浏览器缓存。

RewriteEngine On
##keep redirection Rules first then keep rest of rules.
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule !.*\.php/?$ %{REQUEST_FILENAME}.php [QSA,L]

##Adding new rule here for non-existing pages here.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/?$ index.php?$1 [QSA,L]

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

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