Rewrite rule for Apache not finding URL?

2019-07-02 12:57发布

Using the answer I received from rcs20 in my previous post when I add this entry to my .htaccess file I see the error 404 Not Found:

Options +FollowSymLinks
RewriteEngine on
RewriteRule ^member\-([0-9]+)\-([^/])\.htm(l)?$ view_profile.php?id=$1 [NC,L]

The URL I'm passing it is:

mysite/member-8222-jane.html

Any idea why this might be happening. My old rewrite rule works fine:

RewriteRule view_profile=(.*)$ view_profile.php?id=$1 

1条回答
Deceive 欺骗
2楼-- · 2019-07-02 13:27

found it:

The + sign needs to be added to [^/] => ([^/]+)

Options +FollowSymLinks
RewriteEngine on
RewriteRule ^member\-([0-9]+)\-([^/]+)\.htm(l)?$ view_profile.php?id=$1 [NC,L]

You can also add the extra chars jane in member-8222-jaane.html by using the $2 like:

RewriteRule ^member\-([0-9]+)\-([^/]+)\.htm(l)?$ view_profile.php?id=$1&extra=$2 [NC,L]
查看更多
登录 后发表回答