Forum Moderators: phranque

Message Too Old, No Replies

Need help with my .htacces file

         

Bermy

1:43 pm on Jan 25, 2005 (gmt 0)

10+ Year Member



Hi everyone,
I'm trying to change my dynamic php page to a static php page. I've been trying for few days now but nothing seen working. So, I want to change my:
#*$!x.com/search/browse.php?cat=1
to something like this:
#*$!x.com/search/browse_1.php

I have 800 pages and some sub pages. I want to change this sub pages:
xxxx.com/search/browse.php?pg_which=2&cat=1
to:
xxxx.com/search/browse_1_2.php

Here are my .htaccess:
RewriteEngine on
RewriteRule ^(.*)\/browse_([0-9]+)\.php$ /$1/browse.php?cat=$2 [L]

So what wrong with my .htaccess and what should I do to get the result?
Thanks for your help!

Marino

8:08 am on Jan 26, 2005 (gmt 0)

10+ Year Member



Try this :

RewriteRule ^(.*/browse)\.php\?pg_which=([0-9]+)&cat=([0-9]+)$ $1_$3_$2.php

I did not test it.

Bermy

1:01 pm on Jan 26, 2005 (gmt 0)

10+ Year Member



Thanks Marino, I try what you send me but still doesn't work. I've been working on this for a week now and everything I try doesn't work. It's a bit strange because I have another .htaccess on my root that work fine so it not because my server doesn't accept .htaccess. I don't know if someone could help me, I really need your help on this!
Regards...

Marino

8:39 pm on Jan 26, 2005 (gmt 0)

10+ Year Member



Strange, it should work.
I've tested with another regexp engine :
Tested string :
[somesite.com...]
Results for ^(.*/browse)\.php\?pg_which=([0-9]+)&cat=([0-9]+)$ :
Group(0) = [somesite.com...]
Group(1) = [somesite.com...]
Group(2) = 2
Group(3) = 1

So $1_$3_$2.php should give :
[somesite.com...]

Is that the result you'd wish to get?

calvinmicklefinger

9:38 pm on Jan 26, 2005 (gmt 0)

10+ Year Member



Bermy,

The first term in the rule is what you receive from the visitor and what you want them to see in the URL, the second is the actual URI that will be used by the server.

The first line in my example below (RewriteBase /) allows you to omit the mydomain.com/ stuff and start with your variables. You may want to consider leaving out the search/browse stuff and just use something like

[mydomain.com...]

Seems less confusing to me. You can insert the search/browse stuff in the second term of the rule.

Try this ... (haven't tested it, so play with it)

RewriteBase /
RewriteRule ^search/browse_([0-9]+)_([0-9]+)\.php$ search/browse\.php?pg_which=$2&cat=$1 [NC,L]

If you go with the example I mentioned, the rule would be ...

RewriteBase /
RewriteRule ^([0-9]+)/([0-9]+)$ search/browse\.php?pg_which=$2&cat=$1 [NC,L]

Or, if you know the number of digits you will be using, (let's say three), you could use the following ...

For a user sending [yourdomain.com...]

You could say ...

RewriteBase /
RewriteRule ^([0-9]{3})([0-9](3})$ search/browse\.php?pg_which=$2&cat=$1 [NC,L]

where the digit inside the curly braces tells the engine how many times to loop through the characters. In this example, $1 would be 123, and $2 would be 456

Remember that the $1 and $2 variables are numbered by the sequence they are created in the first term. You can use them in any sequence and as many times as you wish, but only on that line (jdmorgan has identified a bug that limits their use after one line).

jdMorgan

12:03 am on Jan 27, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Bermy,

Welcome to WebmasterWorld!

The discussion in this recent thread [webmasterworld.com] may help you get started.

Jim

Bermy

12:32 pm on Jan 27, 2005 (gmt 0)

10+ Year Member



Many thanks for your help! I've made many try and now it seem to work so/so. When we browse on the directory and click on a subcategory, it's keep sending the visitor at the url finishing with browse.php?cat=? like this exemple [tekclick.com...] but we cant go on this address to : [tekclick.com...] . so it seen that my .htaccess work but doesn't automaticly change the address. What sould I add in my .htaccess to change automaticly the url? Here is my .htaccess:

RewriteEngine on
RewriteRule ^(.*)\/browse_([0-9]+)\.php$ /$1/browse.php?cat=$2 [L]

order allow,deny
deny from 68.184.84.58
deny from 68.184.84.58.
deny from 58.84.184.68
deny from 64.124.85.93
deny from 64.124.85.201
deny from 64.124.85.202
deny from 64.124.85.203
deny from 64.124.85.204
deny from 64.124.85.205
deny from 64.124.85.206
deny from 64.124.85.207
deny from 64.124.85.208
deny from 64.124.85.209
deny from 64.124.85.210
deny from 64.124.85.255
allow from all

<Files .htaccess>
order allow,deny
deny from all
</Files>


Thanks for your help... I wait for your answer!