FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


mod_rewrite code





phileplanet
I have managed to rewrite
Code:

x/downloads/Software/MPUI/
x/downloads/Software/
x/downloads/
x/

to
Code:

/index.php?section=downloads&subsection=Software&view=MPUI
/index.php?section=downloads&subsection=Software
/index.php?section=downloads
/index.php

Here is my current .htaccess:
Code:

RewriteEngine on
RewriteBase /
RewriteRule ^\.htaccess$ - [F]
RewriteCond %{HTTP_USER_AGENT} ^EmailSiphon
RewriteRule ^.*$ - [F]
RewriteRule ^x/(.*)/(.*)/(.*)/$ /index.php?section=$1&subsection=$2&view=$3
RewriteRule ^x/(.*)/(.*)/$ /index.php?section=$1&subsection=$2
RewriteRule ^x/(.*)/$ /index.php?section=$1
RewriteRule ^x/$ /index.php
ErrorDocument 404 /404.php

I don't want the x/ to be in the URL. For example, rather than
Code:

spare.phileplanet.com/x/downloads/Software/

I would like
Code:

spare.phileplanet.com/downloads/Software/
.
I have tried removing the x/ from the .htaccess file but then everything after the second level (x/downloads/Software/) messes up.
Anybody want to help me?
phileplanet
*bump*

I really need this code. I will give Frih$ if needed.
Kaneda
It's a long time since I've used mod_rewrite, but I'll give it a shot...

First of all, don't remove "x/", you'll at least want to keep the "/" - not having it might be what causes the problem...

Secondly, regular expression-wise, ([^/]+) would be better than (.*) (the former means "match at least one character that isn't a slash (and grab it for backreferences)"). I assume you always want at least one character between the slashes. I.e., no URL like: somesite.com///s/ Wink

So, maybe try...

Code:
RewriteRule ^/([^/]+)/([^/]+)/([^/]+)/$ /index.php?section=$1&subsection=$2&view=$3
RewriteRule ^/([^/]+)/([^/]+)/$ /index.php?section=$1&subsection=$2
RewriteRule ^/([^/]+)/$ /index.php?section=$1
RewriteRule ^/$ /index.php


Should, by all my estimations (but I can't test it, don't have Apache installed on this PC)... work...
phileplanet
Kaneda wrote:
It's a long time since I've used mod_rewrite, but I'll give it a shot...

First of all, don't remove "x/", you'll at least want to keep the "/" - not having it might be what causes the problem...

Secondly, regular expression-wise, ([^/]+) would be better than (.*) (the former me...

I managed to get it to work by taking out the x/ and adding a [L] to the end of each line. Thanks though.
Related topics
De da vinci code
add some media code in the forum
mod_rewrite
PHP: Directory listing code
Problam about google ad code
.htaccess instead of mod_rewrite
[SOLVED] Using mod_rewrite.
75FRIH$ Mod_Rewrite Code
Force reload CSS
Is mod_rewrite enabled?
Apache mod_rewrite
need help with mod_rewrite rules
"site/page" DIFFERENT from "site/page/"?
Apache mod_rewrite questions.
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.