0

Hi, I'm trying to add a condition to my htaccess file but it seems to only match if I use %{REQUEST_URI} !^/?.+$ . If however I add %{REQUEST_URI} !^/?B.+$ it will never match. Also the full code showing what I am trying to achieve is as follows:

[B]RewriteEngine On[/B]
[B]RewriteRule[/B] ^$ /wiki/index.php [L,QSA]
[B]rewriteCond[/B] %{REQUEST_URI} !^/?Botindex/[^/]+/.+$ [NC]
[B]RewriteRule[/B] ^([^/]+)$ /wiki/index.php?title=$1 [L]

Does anybody know why the rewrite condition just won't match on some of the simplest syntaxes. This is really bugging me. Thanks.

4
Contributors
8
Replies
10
Views
8 Years
Discussion Span
Last Post by kingkong111411
0

I just discover that using RewriteCond %{REQUEST_URI} !^\/?\B.*$ [NC] will work but adding the rest of the string after the \B will make it stop working. Any reason?

0

I just discovered \B will match multiple characters and that's why \B worked. But still I can't get my code to match. Does anybody know the problem. I have even tried the following without any success:

Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^$ /wiki/index.php [L,QSA]
RewriteCond %{REQUEST_URI} !^/Botindex/(.+)$ [NC]
RewriteRule ^([^/]+)$ /wiki/index.php?title=$1 [L,QSA]

Anybody please?

I just discover that using RewriteCond %{REQUEST_URI} !^\/?\B.*$ [NC] will work but adding the rest of the string after the \B will make it stop working. Any reason?

0

I managed to fix the url although I'm not 100% happy with the solution. But now I have a really weird problem that I have never seen in my life. I have a url variable named $_GET['id'] which equals the string value of 202693 . I then run the following script.

$r=mysql_query('SELECT * FROM `faq_data` WHERE `id`="'.$_GET['id'].'" AND `forum`="'.mysql_real_escape_string($_GET['forum']).'"',$con1) or die(mysql_error());
    $data=mysql_fetch_assoc($r);
    if ($_GET['id']=='202693') {
        $content.='<script>alert("\'SELECT * FROM `faq_data` WHERE `id`=\"'.$_GET['id'].'\" AND `forum`=\"'.mysql_real_escape_string($_GET['forum']).'\"\'");</script>';
        }
    print_r($data);

Now with the above script, it displays the message with the query but it won't print the array $data. However the id 202693 does exist in the database. Does anybodyh know what's happening?

0

After 12 hours non stop of working at this problem I have solved it for the time being but does anybody know how to remove the annoying dash in the following .htaccess file:

Options +FollowSymlinks
RewriteEngine On

RewriteRule ^$ /wiki/index.php [L]
RewriteRule ^Botindex-Topics_-_(.+)$ /wiki/index.php?title=Botindex-Topics_-_$1 [L,QSA]
RewriteRule ^BotTopics/([^/]*)/([0-9a-zA-Z]+)$ /wiki/extensions/blah/indexarticle.php?forum=$1&id=$2 [L,QSA]

RewriteCond %{REQUEST_FILENAME} !-f
[B]RewriteRule ^-(.*)$ /wiki/index.php?title=$1 [L,QSA][/B]
RewriteRule ^Language=([^/-]*)$ /wiki/index.php?title=$1 [L,QSA]

The part in bold and red needs to somehow be changed so it doesn't have a dash at the beginning but still allow the other htaccess rules to work. Thanks.

0

I really hate trying to rewrite urls. I found using a basic rewrite and having php parse the url is much easier.

I use a url class that parse the url. This makes it so you can change the rewrite via php and not have to edit .htaccess. Dynamically I could change my rewrite of /key/value/key/value to key-value-key-value.html and it will update all the links in my app.

Here is the rewrite I use:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]

This is kind of how the major frameworks do it.

If you want, I can post my url class.

Edited by somedude3488: n/a

0

Yes please kk - looks interesting. Looks a lot easier that the phaph that I've been producing. Nice.

0

I managed to make a work around for mediawiki which allows both custom directories and for the path of the mediawiki title to be at the root url. My solved htaccess file is as follows:

Options[B] +[/B]FollowSymlinks
RewriteEngine On

RewriteRule ^-(.*)$ http://syntax.cwarn23.info/$1 [L,R=301]
RewriteRule ^$ /wiki/index.php [L]
RewriteRule ^Botindex-Topics_-_(.+)$ /wiki/index.php?title=Botindex-Topics_-_$1 [L,QSA]
RewriteRule ^BotTopics/([^/]*)/([0-9a-zA-Z]+)$ /wiki/extensions/danibot/indexarticle.php?forum=$1&id=$2 [L,QSA]

RewriteRule ^Language=([^/-]*)$ /wiki/index.php?title=$1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^LB-][^oa][^tn].*)$ /wiki/index.php?title=$1 [L,QSA]

Hope that is useful for anyone reading this in the future.
*Solved*

Edited by cwarn23: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.