2017-10-07 50 views
0

我做了mod_rewrite真正的基本规则,并不能使其工作。 我想要的网址: “https://www.example.com/index.php?req=login” 是 “https://www.example.com/loginmod_rewrite规则不起作用没有文件扩展名

的htaccess文件是这样的:

RewriteEngine On 
RewriteRule ^([^/]*)$ /index.php?req=$1 [L] 

我重定向到的index.php,但如果我打印$ _GET的结果是这样的:

Array ([req] => index.php) 

当它应该是“登录”,而不是“的index.php”

如果我把一个扩展通缉规则为.html和使得R因为这个:

RewriteRule ^([^/]*)\.html$ /index.php?req=$1 [L] 

它工作得很好,我得到了“请求”键与“登录”值想要的。

不能弄清楚如何使它无延长地工作。

更新: 添加在模式的开头部分串也能正常工作:

RewriteRule ^request/([^/]*)$ index.php?req=$1 [L] 

回答

0

试试这个

RewriteEngine On 
RewriteBase/
RewriteCond %{REQUEST_URI} /([a-z\-A-Z]+) 
RewriteRule (.*) index.php?req=%1 [L] 
+0

这也将mach'/page/subpage'并将其重写为'index.php?req = page'我不确定这是否是有意的,但是/ page1'将不起作用 – Webdesigner

1

的一点是你必须从重写排除的index.php。

RewriteEngine On 
RewriteBase/
RewriteCond %{REQUEST_URI} !^/?index\.php$ 
RewriteRule ^([^/]*)$ index.php?req=$1 [L] 

每改写一次孔之后都会再次完成。所以第一次重写看起来像这样:
/login/index.php?req=login但现在服务器正在检查他是否必须为新的URL做另一个规则。如果你排除index.php比我们没事。

当然,如果你添加一些额外的字符串(例如.htmlrequest/)未在index.php包括比你是不是做了第二轮,但是这仅仅是一个解决方法不是解决办法。

+0

好答案+1。 – starkeen