2016-11-01 19 views
1

我有一个网址website.com/app/有一个index.php在目录和.htaccess文件。 我想使这个网址到一个干净的URL如何创建干净的URL使用.htaccess的2参数或1

website.com/app/?app=app1&id=12345 

website.com/app/app1/12345 

我能与此规则

RewriteEngine On 
# Don't match real existing files so CSS, scripts, images aren't rewritten 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 

RewriteRule ^([^/]+)/([^/]+) index.php?app=$1&id=$2 [L] 
RewriteRule ^([^/]+)index.php?app=$1 [L] 

来实现这一点,但我也希望能够访问此网页的网页

website.com/app/app1 

这样它就意味着website.com/app/?app=app1但是目前我得到“Object not found!”当试试这个。 谢谢!

+0

你可以在上面的规则前面有一个更具体的规则,只接受一个get参数,或者在正则表达式的第二个捕获组上应用''''运算符。 – arkascha

回答

1

试试这个RewriteRule,就会留下你的网址:website.com/app/app1

RewriteEngine On 
RewriteRule ^app/([^/]*)$ /app/?app=$1 [L] 
0

我在这里回答我自己QN:

RewriteEngine On 
# Don't match real existing files so CSS, scripts, images aren't rewritten 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 

RewriteRule ^([^/]*)$ /apps/?app=$1 [L] 
RewriteRule ^([^/]*)/([^/]*)$ index.php?app=$1&id=$2 [L] 

不客气