I've got little problem that I am not sure how to fix. I am using htaccess file to rewrite my url to shorter links. For example I am using this rule:
我没有问题,我不知道如何解决。我正在使用htaccess文件将我的URL重写为更短的链接。例如,我正在使用此规则:
RewriteEngine On
RewriteRule ^client/(.*)/?$ pages/client.php?action=$1 [L,QSA]
but I wanted to also pass second argument to that URL so I made this:
但是我也希望将第二个参数传递给该URL,所以我做了这个:
RewriteRule ^client/(.*)/(.*)/?$ pages/client.php?action=$1&view=$2 [L,QSA]
so I could access URL like:
所以我可以访问URL,如:
/client/action_1/view_2
without any problems but when I skipped second argument and only accessed:
没有任何问题,但当我跳过第二个参数并且只访问:
/client/action_1/
then it was impossilbe and resulted in 404.
然后它是impossilbe并导致404。
How to make a change to that RewriteRule so I can access both:
如何更改RewriteRule以便我可以同时访问:
/client/action_1/view_2
/client/action_1/
and it would rewrite to:
它会重写为:
pages/client.php?action=$1&view=$2
1 个解决方案
#1
You can have 2 separate rules to handle 2 clean URLs:
您可以有2个单独的规则来处理2个干净的URL:
RewriteEngine On
RewriteRule ^client/([^/]+)/?$ pages/client.php?action=$1 [L,QSA,NC]
RewriteRule ^client/([^/]+)/([^/]+)/?$ pages/client.php?action=$1&view=$2 [L,QSA,NC]
#1
You can have 2 separate rules to handle 2 clean URLs:
您可以有2个单独的规则来处理2个干净的URL:
RewriteEngine On
RewriteRule ^client/([^/]+)/?$ pages/client.php?action=$1 [L,QSA,NC]
RewriteRule ^client/([^/]+)/([^/]+)/?$ pages/client.php?action=$1&view=$2 [L,QSA,NC]