重写规则参数与文件扩展名结合
每天都有一个问题,我该如何重写.htaccess。我发现缺少有关.htaccess规则的信息,并且找不到以下答案:
RewriteEngine On
RewriteRule ^user/([^/]*)$ /user.php?username=$1 [L]
现在,此规则确保users.php?username = hello reprites as user.php/hello hello 但是我如何摆脱.php?我是否添加以下条件并在没有.php的情况下更改上一个条件?所以
RewriteEngine On
RewriteRule ^user/([^/]*)$ /user?username=$1 [L]
还是我保留前一个PHP?我发现以下条件可以删除PHP。
RewriteEngine on
RewriteCond %{THE_REQUEST} /([^.]+)\.php [NC]
RewriteRule ^ /%1 [NC,L,R]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [NC,L]
但是,它与user.php不合时宜。
如何重写user.php?用户名= hello to user/hello,同时将.php文件作为index.php的正常文件索引。
There is the daily question again, how can I rewrite my .htaccess. I found there is a lack of information about the .htaccess rules and can not find an answer to the following:
RewriteEngine On
RewriteRule ^user/([^/]*)$ /user.php?username=$1 [L]
Now this rule makes sure that users.php?username=hello rewrites as user.php/hello
but how can I get rid of the .php? Do i add the following condition and change the previous condition without the .php? so
RewriteEngine On
RewriteRule ^user/([^/]*)$ /user?username=$1 [L]
Or do I keep the previous one WITH php? I found the following condition to remove the php.
RewriteEngine on
RewriteCond %{THE_REQUEST} /([^.]+)\.php [NC]
RewriteRule ^ /%1 [NC,L,R]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [NC,L]
however it is NOT working in combination with the user.php.
How can I rewrite user.php?username=hello to user/hello and in the same time have normal .php files as index.php to index.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论