斜线后如何获得url的最后一部分作为获得php的值

发布于 2025-02-04 05:49:25 字数 453 浏览 3 评论 0原文

我的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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦中的蝴蝶 2025-02-11 05:49:25
 重写 ^([[A-ZA-Z0-9 _-]+)+)/$ index.php?slug = $ 1
 

但是错误是http:// localhost/event_manage/hello

上面的规则假设您的URL在尾随的斜线中结束,但是您的示例却没有,因此它将无法匹配并导致404(因为它不是将请求重写为index.php)。

它应该是:

RewriteRule ^([\w-]+)$ index.php?slug=$1 [L]

\ w(单词字符)只是一个速记字符类,与[A-ZA-Z0-9 _]相同。

如果添加更多指令,则需要l标志。

假设.htaccessindex.php位于/event_manage subdirectory中。


旁边:

  http:// localhost/event_manage?slug = hello
 

由于/event_manage是一个物理目录,因此该URL应为http://localHost/event_manage/?slug = hello(在目录名称之后带有落后斜线)。如果您省略了拖延斜线,则MOD_DIR将用301重定向附加尾斜线。

RewriteRule ^([a-zA-Z0-9_-]+)/$ index.php?slug=$1

but error is http://localhost/event_manage/hello

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:

RewriteRule ^([\w-]+)$ index.php?slug=$1 [L]

\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 and index.php are located inside the /event_manage subdirectory.


Aside:

http://localhost/event_manage?slug=hello

Since /event_manage is a physical directory, this URL should be http://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.

只为一人 2025-02-11 05:49:25

这对我有用:

RewriteEngine on
RewriteRule ^([a-zA-Z0-9_-]+)$ index.php?slug=$1

This worked for me:

RewriteEngine on
RewriteRule ^([a-zA-Z0-9_-]+)$ index.php?slug=$1
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文