• Some users have recently had their accounts hijacked. It seems that the now defunct EVGA forums might have compromised your password there and seems many are using the same PW here. We would suggest you UPDATE YOUR PASSWORD and TURN ON 2FA for your account here to further secure it. None of the compromised accounts had 2FA turned on.
    Once you have enabled 2FA, your account will be updated soon to show a badge, letting other members know that you use 2FA to protect your account. This should be beneficial for everyone that uses FSFT.

Apache mod_rewrite not escaping ?

tino

n00b
Joined
Jun 9, 2008
Messages
30
Hi,

I have an issue with mod_rewrite within apache. It doesn't seem to want to escape the ? character. I have the following redirects set up.
Code:
RewriteEngine on
RewriteRule ^index.php\?$  /wp/index.php
RewriteRule ^index.php\?/articles/$  /wp/index.php?cat=9
RewriteRule ^index.php\?/news/$  /wp/index.php?cat=8
RewriteRule ^index.php\?/forums/$  /smf/index.php?
RewriteRule ^index.php\?/forums/viewforum/([^/\.]+)/?$  /smf/index.php?board=$1
RewriteRule ^index.php\?/forums/viewthread/([^/\.]+)/?$ /smf/index.php?topic=$1

However it doesn't want to escape the ? , if I do this

Code:
RewriteEngine on
RewriteRule ^index.php$     /wp/index.php
RewriteRule ^index.php/articles/$   /wp/index.php?cat=9
RewriteRule ^index.php/news/$   /wp/index.php?cat=8
RewriteRule ^index.php/forums/$   /smf/index.php?
RewriteRule ^index.php/forums/viewforum/([^/\.]+)/?$    /smf/index.php?board=$1
RewriteRule ^index.php/forums/viewthread/([^/\.]+)/?$   /smf/index.php?topic=$1

An don't have the ? in the url it works, unfortunately the previous site and system used the ? so I have to redirect with that still visible and used.

Is there anything I'm missing?

Thanks in advance for any replies
Code:
 
Last edited:
Thanks for the link, I'm afraid I still can't seem to work it out.

Surely it must be possible to escape the ? after the index.php in the first block of code.

Or am I misunderstanding this entirely.
 
You can't escape the ? because it's not there. The data available in the rewrite rule does not include the query string. You can only compare against the query string using a rewrite condition and the query string variable.

Here's the code you want:

Code:
RewriteEngine on

RewriteCond %{QUERY_STRING} ^$
RewriteRule index.php  /wp/index.php

RewriteCond %{QUERY_STRING} ^/articles/$
RewriteRule index.php  /wp/index.php?cat=9

RewriteCond %{QUERY_STRING} ^/news/$
RewriteRule index.php  /wp/index.php?cat=8

RewriteCond %{QUERY_STRING} ^/forums/$
RewriteRule index.php  /smf/index.php?

RewriteCond %{QUERY_STRING} ^/forums/viewforum/([^/\.]+)/?$
RewriteRule index.php  /smf/index.php?board=%1

RewriteCond %{QUERY_STRING} ^/forums/viewthread/([^/\.]+)/?$
RewriteRule index.php /smf/index.php?topic=%1
 
Thanks alot for your reply.

I ran in to some issues with the following query.

Code:
RewriteCond %{QUERY_STRING} ^$
RewriteRule index.php  /wp/index.php

As it would rewrite the following query as it noticed the index.php at the end.

Code:
RewriteCond %{QUERY_STRING} ^/forums/$
RewriteRule index.php  /smf/index.php?


However I got round that by just inserting a index.php file and redirecting with that instead of using Apache. Probably not the prettiest solution but it worked.

All the other strings worked perfectly tho.

Thanks alot for your time, effort and help.
 
Back
Top