htaccess - 获取请求后获取所有字符

The real content is at domain.com/view.php?id=image_id

I want to have it be accessible with domain.com/view/image_id

The following is currently there to get the .php file extensions out.

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

Appending the following to the htaccess doesn't work:

RewriteRule ^view/([A-Za-z0-9]+). /view.php?id=$1 [L, QSA]

Also, I am fine with having everything after view.php? (view.php?id=) get taken into the php file and from there I can separate everything out by slashes and implement their data.

I have looked at many solutions here on stackoverflow and elsewhere but either they do not apply to me or something is wrong with my server. Either way, I get an internal 500 server error. Thanks.

You need to place the view rule before the more general php extension rule:

RewriteEngine On

RewriteRule ^view/([A-Za-z0-9]+)$ /view.php?id=$1 [L,QSA]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

Also, you don't want that space after the L,.

^view/([A-Za-z0-9]+).
                    ^---single character wildcard

That . at the end there is matching/consuming one of your ID values, so if the url is

/view/foobarbaz

Your capture group will actually be foobarba, and the z gets chopped off, producing

/view.php?id=foobarba

Your 500 Internal Server Error is the result of a redirect loop.

This is because your rule will always be true, because you are redirecting back to the same page.

You need to exclude the resultant link by adding a rule with ^! before all the rest.