斜线后如何获得url的最后一部分作为获得php的值
我的URL看起来像:http:// localhost/event_manage?slug = hello
和最后一个值,如hello
因此,该页面在index.php
中,当我去http:// localhost/event_manage/hello
时,因为没有文件夹为nesh代码>。 但是我想要这个hello
就像我去http:// localhost/event_manage/hello
时,
在.htaccess
file:
RewriteEngine on
RewriteRule ^([a-zA-Z0-9_-]+)/$ index.php?slug=$1
我 它仍然显示错误,无法传递该值!
My url is look like: http://localhost/event_manage?slug=hello
and last value as like hello
So that page is in index.php
when i go http://localhost/event_manage/hello
and shows error because there is no folder as named hello
.
But i want this hello
is like GET value When I go http://localhost/event_manage/hello
I tried in .htaccess
file:
RewriteEngine on
RewriteRule ^([a-zA-Z0-9_-]+)/$ index.php?slug=$1
But it still shows error and couldn't pass the value!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
上面的规则假设您的URL在尾随的斜线中结束,但是您的示例却没有,因此它将无法匹配并导致404(因为它不是将请求重写为
index.php
)。它应该是:
\ w
(单词字符)只是一个速记字符类,与[A-ZA-Z0-9 _]
相同。如果添加更多指令,则需要
l
标志。假设
.htaccess
和index.php
位于/event_manage
subdirectory中。旁边:
由于
/event_manage
是一个物理目录,因此该URL应为http://localHost/event_manage/?slug = hello
(在目录名称之后带有落后斜线)。如果您省略了拖延斜线,则MOD_DIR将用301重定向附加尾斜线。The above rule assumes your URL ends in a trailing slash, but your example does not, so it will fail to match and result in a 404 (because it's not rewriting the request to
index.php
).It should be:
\w
(word characters) is just a shorthand character class, the same as[a-zA-Z0-9_]
.You need the
L
flag if you add any more directives.This assumes
.htaccess
andindex.php
are located inside the/event_manage
subdirectory.Aside:
Since
/event_manage
is a physical directory, this URL should behttp://localhost/event_manage/?slug=hello
(with a trailing slash after the directory name). If you omit the trailing slash then mod_dir will append the trailing slash with a 301 redirect.这对我有用:
This worked for me: