Jump to content

Expanding my mod_rewrite


JasonO

Recommended Posts

Hey everyone,

 

Currently I have the following mod_rewrite:

 

RewriteEngine On
RewriteRule ^([A-Za-z0-9-]+)/?$ index.php?page=$1 [L]

 

At the moment this converts any URL in the following format:

http://domain.com/pagename

to

http://domain.com/index.php?page=pagename

 

Works great! However, I need to get a 2nd parameter into my URL, but no matter how much I read on it and how much I tweak it (constant server errors etc) I can't get the following:

 

http://domain.com/firstpage/secondpart

to end up as

http://domain.com/index.php?page=firstpage&act=secondpart

 

Anyone able to point me down the right path? It's driving me mad!  :-\ This is the closest I think I've got, but still server error.

RewriteEngine On
//RewriteRule ^([A-Za-z0-9-]+)/?$ index.php?page=$1 [L]

RewriteRule ^([a-zA-Z0-9-]+)/([a-zA-Z0-9]+)$ /index.php?page=$1&act=$2
RewriteRule ^([a-zA-Z0-9-]+)$ /index.php?page=$1

 

Regards,

Jason

Link to comment
https://forums.phpfreaks.com/topic/189943-expanding-my-mod_rewrite/
Share on other sites

Yeah, I figured that out after posting. Couldn't edit it though and didn't want to double post.

 

I've managed to not get an error to show, although now I just get a 404 error error with a 2nd variable. I actually want a 3rd one possible too if I can.

 

RewriteRule ^([a-zA-Z0-9-]+)/?$/^([a-zA-Z0-9]+)/?$ /index.php?page=$1&act=$2
RewriteRule ^([A-Za-z0-9-]+)/?$ index.php?page=$1 [L]

 

I keep playing around with the symbols to try and get it to work but no joy :(

This is should work fine

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule ^([a-zA-Z0-9-]+)/([a-zA-Z0-9]+)/?$ /index.php?page=$1&act=$2 [L]
RewriteRule ^([a-zA-Z0-9-]+)/?$ /index.php?page=$1 [L]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.