Mod_rewrite question

SpaceshipSpaceship
SpaceshipSpaceship
Namecheap AuctionsNamecheap Auctions
Watch

Barrucadu

Established Member
Impact
64
I want to make all my url's in the form "index.php?p=<name of page>&<additional info>" into "<name of page>.php?<additional info>"

I have figured out the regex to match all my pagess (i think)
Code:
index.php?p=[a-zA-Z0-9]{1,}&[a-zA-Z0-9&=]{1,}
How would I get that into mod_rewrite format?
 
0
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
Erm lemme see if i can remember this right...

Code:
RewriteRule ^([a-zA-Z0-9]+)\.php?([a-zA-Z0-9&=]+)$ index.php?p=$1&catid=$1&$2 [L]

Thats how you said you wanted it. Although it might be easier if you just did:


Code:
RewriteRule ^(.*)\.php?(.*)$ index.php?p=$1&$2 [L]

Although then again if you did the & sign for <name of page>&<additional info> you would need a second variable.

Code:
RewriteRule ^(.*)\.php?(.*)$ index.php?p=$1&additionalinfo=$2 [L]

^^^
That is how i would do it. Be sure to enclose that rule in tags like:

Code:
<IfModule mod_rewrite.c>
and then closing tags like:

Code:
</IfModule>
 
0
Close
mod_rewrite enable "path/<name of page>/<additional info>.html" for your better search engine results right?
 
0
Close
Yeah that would be better masking it as a html, but if he wants to keep it as a php file then fine ;)

For example on one of my gaming sites i use mod_rewrite:

Code:
RewriteRule ^showcat/([0-9]+)/([0-9]+)/(.*)\.html$ index.php?action=showcat&catid=$1&parentid=$2 [L]

so if they do games/showcat/(catid)/(gameid)/(gamenamejustfordisplay).html

it will redirect it all to the php file. Very fun to do ^^
 
0
Close
CatchedCatched

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

Switch between accounts
You can now stay logged in to more than one NamePros account in the same browser. Click your avatar, then "Accounts in this browser", to...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back