开发者

How to make this simple mod_rewrite work

开发者 https://www.devze.com 2023-02-05 18:47 出处:网络
I\'m a bit of a newb so excuse the very simple challenge I\'m having. Basically, i\'m using friendly url\'s and you can access articles on my site like so:

I'm a bit of a newb so excuse the very simple challenge I'm having.

Basically, i'm using friendly url's and you can access articles on my site like so:

url.com/articles/article_name

Which translates on the server as

url.com/articles.php?article_url=ar开发者_Python百科ticle_name

If however, you visit

url.com/articles

It brings up an index of the articles. This all works as I'd planned.

The problem is when I load up

url.com/articles/

It causes some headaches. Ideally, '/articles' and '/articles/' would both load up an index.

My rewrite lines look like this:

RewriteRule ^articles$ articles.php
RewriteRule ^articles/(.*)$ articles.php?article_url=$1

Any ideas??


From memory, you need to make the trailing slash optional on the first rule:

RewriteRule ^articles/?$ articles.php
RewriteRule ^articles/(.+)$ articles.php?article_url=$1


RewriteRule ^articles/*$ articles.php
RewriteRule ^articles/(.+)$ articles.php?article_url=$1
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号