.htaccess RewriteRule中的数字值(Numeric value in .htaccess RewriteRule)

编程入门 行业动态 更新时间:2024-10-28 21:22:46
.htaccess RewriteRule中的数字值(Numeric value in .htaccess RewriteRule)

我经常搜索,但没有找到任何东西。

我正在使用codeigniter。 我目前的网址是: base_url/content_controller/content_download/download_id 但是,我需要这样做: base_url/download_id

因为下载ID是数字,我的.htaccess不起作用。

RewriteRule ^download/content/2$ 2 [L]

如果没有.htaccess,请告诉我如何解决这个问题。

I've searched a lot, but didn't find anything.

I am using codeigniter. my current url is: base_url/content_controller/content_download/download_id but, I need to do it: base_url/download_id

as download id is numeric, my .htaccess doesn't work.

RewriteRule ^download/content/2$ 2 [L]

Please tell me how to solve that and if there is any way to do it without .htaccess.

最满意答案

你的意思是这样的吗?

RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([0-9]+)$ /download/content/$1 [L]

因此,如果您请求http://example.com/123 ,则URI将被重写为/download/content/123 。

Thanks Jon, I tried several times but multiple rule conflicts. So I do it in another way. when I hit the URL http://www.example.com/2/ it shows Not Found. So, I use 404 controller to handle the numeric value. Finally I have done it.

更多推荐

本文发布于:2023-08-01 02:46:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1354060.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数字   htaccess   RewriteRule   Numeric

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!