NameSilo

Mod_rewrite question

Spaceship Spaceship
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
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
Unstoppable DomainsUnstoppable Domains
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
•••
mod_rewrite enable "path/<name of page>/<additional info>.html" for your better search engine results right?
 
0
•••
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
•••
Dynadot — .com Registration $8.99Dynadot — .com Registration $8.99
Appraise.net

We're social

Unstoppable Domains
Domain Recover
DomainEasy — Live Options
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back