问题描述:

I have a situation where I want to actually see the url variable even though the rest of my htaccess site uses readable URLS.

The issue is that it is simply showing up as a page not found...

This works...

RewriteRule ^files/(.+)/from_all_files/$ pages/file.php?slug=$1&from=all-files

This does not work

RewriteRule ^files/(.+)?from=all-files$ pages/file.php?slug=$1&from=all-files

Im looking for the second one to work.

网友答案:

You cannot check the query string in a RewriteRule, which can only see the REQUEST_URI. You need to use the following instead:

RewriteCond %{QUERY_STRING} ^from=all-files$ [NC]
RewriteRule ^files/(.+)$ pages/file.php?slug=$1 [QSA,L]

When you request http://example.com/files/some-file?from=all-files, the request will be internally rewritten to pages/file.php?slug=some-file&from=all-files. The Query String Append flag (QSA) will append the current query string to the one you're rewriting to.

相关阅读:
Top