简体   繁体   中英

Difficult problems with mod_rewrite

I have a difficult problem: In my .htaccess I have the following RewriteRules which do not function.

RewriteRule u/(.*)/ user.php?u=$1 [L,QSA]
    RewriteRule u/(.*) user.php?u=$1 [L,QSA]
    RewriteRule user/(.*)/ user.php?u=$1 [L,QSA]
    RewriteRule user/(.*) user.php?u=$1 [L,QSA]
    RewriteRule view/(.*)/ view.php?file=$1 [L,QSA]
    RewriteRule view/(.*) view.php?file=$1 [L,QSA]
    RewriteRule show/(.*)/ show.php?img=$1 [L,QSA]
    RewriteRule show/(.*) show.php?img=$1 [L,QSA]
    RewriteRule report/(.*) report.php?img=$1 [L,QSA]
    RewriteRule report/(.*)/ report.php?img=$1 [L,QSA]
    RewriteRule search/tag/(.*) search.php?t=$1 [L,QSA]
    RewriteRule search/tag/(.*)/ search.php?t=$1 [L,QSA]
    RewriteRule search/(.*) search.php?q=$1 [L,QSA]
    RewriteRule search/(.*)/ search.php?q=$1 [L,QSA]
    RewriteRule bug/view/(.*)/ bug.php?view=$1 [L,QSA]
    RewriteRule bug/view/(.*) bug.php?view=$1 [L,QSA]
    RewriteRule bug/(.*) bug.php?step=$1 [L,QSA]
    RewriteRule bug/(.*)/ bug.php?step=$1 [L,QSA]

However, when I enter a RewriteRule as

RewriteRule ^ http://example.com [R, L]

I will be forwarded, so it works.

Solutions such as

RewriteRule u/(.*)/ http://example.com/user.php?u=$1 [L,QSA]

do not work. Also

RewriteRule /u/(.*)/ user.php?u=$1 [L,QSA]

or the like were not successful.

I have the problem since I recently moved to a new server. However, everything seems to be fine with the configuration.

Does anyone have an idea what I'm doing wrong?

Did you search for a possible answer?

I found this: Why does this RewriteRule work with [R] but not with [QSA,L]?

It seems that:

The FastCGI version when paired with Apache 2.2 doesn't seem to like the rewriterule index.php/$1. Instead it prefers index.php?$1 but some CMS don't like that. The CMS I am using does not like that. So undone's comment to use ?$1 was on the right track, but because I had no explanation, and the CMS I am using (Open Journal Systems) does not work with the pathinfo stuff after a ?, then it was just not working.

The solution was to change from FastCGI to just regular CGI.

check the other answers under that URL, they have valid points, that might help your case.

To me it seems like you are using a wrong syntax. Try to put your pattern in double quotes and see if it works (remember: the pattern in RewriteRule is a Regular Expression ). Like this:

 RewriteRule "u/(.*)/" "http://example.com/user.php?u=$1" [L,QSA]

Or a better way is to enclose your patterns in: ^ (as start of string) and $ (as end of string):

 RewriteRule ^u/(.*)$ http://example.com/user.php?u=$1 [L,QSA]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM