简体   繁体   English

多个重写规则不起作用

[英]Multiple rewrite rule not working

Well URL rewriting is nightmare and I am having that for many days. 好吧,URL重写是一场噩梦,而且我已经经历了很多天。
I am trying to rewrite url like: 我正在尝试像这样重写网址:

  • example.com/playground.php?room=abc123 TO example.com/room/abc123 example.com/playground.php?room=abc123 example.com/room/abc123
  • example.com/index.php?room=abc123&action=join TO example.com/join/abc123 example.com/index.php?room=abc123&action=join example.com/join/abc123

I am being able to successfully rewrite the first URL (as in the first case) but am not being able to rewrite the second URL properly. 我能够成功重写第一个URL(如第一种情况),但无法正确重写第二个URL。 It is being rewritten as example.com/room/join/abc123 . 它被重写为example.com/room/join/abc123 I understand that the first rule is being applied for both cases and then the execution of the htaccess stops. 我知道这两种情况都适用第一个规则,然后htaccess的执行停止。 But then how to manage to get the desired solution? 但是,如何设法获得所需的解决方案呢?

HTACCESS .htaccess的

RewriteBase /
RewriteEngine On

RewriteCond %{REQUEST_FILENAME}.php !-f
RewriteRule ^room/([A-Za-z0-9]+)$ playground.php?room=$1 [L]

RewriteCond %{REQUEST_FILENAME}.php !-f
RewriteRule ^join/([A-Za-z0-9]+)$ index.php?room=$1&action=join [L]

You problem is not in the URL rewriting, but it has to do with your playground.php . 您的问题不在于URL重写,而与您的playground.php It has relative URLs instead of absolute URLs. 它具有相对URL而不是绝对URL。 Please change join/abc123 to /join/abc123 . 请将join/abc123更改为/join/abc123

Also there is a tiny error in your .htaccess 您的.htaccess也有一个小错误

You should change 你应该改变

RewriteCond %{REQUEST_FILENAME}.php !-f

to

RewriteCond %{REQUEST_FILENAME} !-f

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

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