Forum Moderators: phranque

Message Too Old, No Replies

Question Mark ? in .htaccess doesn't work

         

lawyer

2:20 am on Nov 3, 2009 (gmt 0)

10+ Year Member



hi, here is the my problem, i can't solve it

my .htaccess file is like that

RewriteRule index.php[b]_[/b]articleid_([0-9]+)_docid=([0-9]+) index.php?articleid=$1&docid=$2

and my link

http://www.example.com/index.php[b]_[/b]articleid_21_docid=87

it works good but it must be like that

http://www.example.com/index.php[b]?[/b]articleid_21_docid=87

when i add ? question mark to .htaccess and then link doesn't work

RewriteRule index.php[b]?[/b]articleid_([0-9]+)_docid=([0-9]+) index.php?articleid=$1&docid=$2

how can i do my link like that with .htaccess

http://www.example.com/index.php[b]?[/b]articleid_21_docid=87

[edited by: encyclo at 2:27 am (utc) on Nov. 3, 2009]
[edit reason] fixed formatting error [/edit]

TheMadScientist

8:23 am on Nov 3, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



A QUERY_STRING is not technically part of the requested location, but rather information passed to the script running at the requested location, so to access information after the ? you must use a condition...

RewriteCond %{QUERY_STRING} ^articleid_([0-9]+)_docid=([0-9]+)$
RewriteRule ^index.php$ /index.php?articleid=%1&docid=%2

lawyer

9:34 am on Nov 3, 2009 (gmt 0)

10+ Year Member



@TheMadScientist, wooow! thank you so much, it worked perfectly, i am very thankful for this. You are very helpful member.

TheMadScientist

9:41 am on Nov 3, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



NP. Glad it's working for you and Welcome to WebmasterWorld!

TheMadScientist

10:06 am on Nov 3, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Here's a bit of an adjustment I forgot to type in my copy / paste / edit above...

RewriteCond %{QUERY_STRING} ^articleid_([0-9]+)_docid=([0-9]+)$
RewriteRule ^index.php$ /index.php?articleid=%1&docid=%2 [L]

You should always use the Last flag [L] unless you know you don't need it. (It stops any following rules from being processed for the request matching the rule, and things can get unexpectedly ugly if it's not used, unless of course you know why you didn't use it...)

lawyer

10:43 am on Nov 3, 2009 (gmt 0)

10+ Year Member



this is very good point, i added [L] thanks so much again.

g1smd

11:34 am on Nov 3, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Don't forget to add the [L] flag to that rule unless you have a very good reason to omit it.

That'll teach me for leaving the thread open for two hours while doing something else, and then replying without refreshing the page.