Problem with links - switches to Friendly URL as always...

New to mod_rewrite? This is a good place to start.

Problem with links - switches to Friendly URL as always...

Postby azplund » Wed May 20, 2009 9:53 am

Hi!


I have search for an answer on this excellent forum, without getting an answer.
Probably because i havent looked as well as i should.
But anyway, here's the problem:

I have tried to do some Friendly URLs, and wondering for:

1st:

I have this link:
index.php?s=medlem&v=someuser

wich i have written this rule for (wich works perfect):
RewriteRule ^([A-Za-z0-9\_][A-Za-z0-9\_\-]+)$ index.php?s=medlem&v=$1 [QSA]

gives: www.site.com/someuser

But i also need a link with another switch, after the "medlem" and "v" switches that looks like this:
index.php?s=medlem&v=azplund&show=fotoalbum

i use this for it, but it doesnt work:
RewriteRule ^([A-Za-z0-9\_][A-Za-z0-9\_\-]+)/([A-Za-z0-9\_][A-Za-z0-9\_\-]+)$ index.php?s=medlem&v=$1&show=$2 [QSA]

should be: www.site.com/someuser/fotoalbum

Thats the first problem.


The second, if i get the above to work, how can i make these rules better:

RewriteEngine On
RewriteRule ^([A-Za-z0-9\_][A-Za-z0-9\_\-]+)/([A-Za-z0-9\_][A-Za-z0-9\_\-]+)$ index.php?s=$1&visa=$2 [QSA,L]
RewriteRule ^([A-Za-z0-9\_][A-Za-z0-9\_\-]+)/([A-Za-z0-9\_][A-Za-z0-9\_\-]+)$ index.php?s=$1&v=$2 [QSA,L]
RewriteRule ^([A-Za-z0-9\_][A-Za-z0-9\_\-]+)/([A-Za-z0-9\_][A-Za-z0-9\_\-]+)$ index.php?s=$1&u=$2 [QSA,L]
RewriteRule ^([A-Za-z0-9\_][A-Za-z0-9\_\-]+)$ index.php?s=medlem&v=$1 [QSA]
RewriteRule ^([A-Za-z0-9\_][A-Za-z0-9\_\-]+)/([A-Za-z0-9\_][A-Za-z0-9\_\-]+)$ index.php?s=medlem&v=$1&show=$2 [QSA]
RewriteRule ^([A-Za-z0-9\_][A-Za-z0-9\_\-]+)/([A-Za-z0-9\_][A-Za-z0-9\_\-]+)/([A-Za-z0-9\_][A-Za-z0-9\_\-]+)$ index.php?s=$1&forum=$2&id=$3 [QSA]
##index.php?s=soek_spel&quest=po&offset=15&typ=Spelets_Namn
RewriteRule ^([A-Za-z0-9\_][A-Za-z0-9\_\-]+)/([A-Za-z0-9\_][A-Za-z0-9\_\-]+)/([A-Za-z0-9\_][A-Za-z0-9\_\-]+)/([A-Za-z0-9\_][A-Za-z0-9\_\-]+)$ index.php?s=$1&quest=$2&offset=$3&typ=$4 [QSA]
RewriteRule ^([a-zA-Z\_]+)/([a-zA-Z\_]+)/([0-9]+) index.php?s=$1&$2&page=$3 [nc]
##RewriteRule ^([A-Za-z0-9\_][A-Za-z0-9\_\-]+)$ index.php?s=visa_forum&forum=$1 [QSA]
RewriteRule ^([A-Za-z0-9\_][A-Za-z0-9\_\-]+)/([A-Za-z0-9\_][A-Za-z0-9\_\-]+)$ index.php?s=$1&$2 [QSA,L]
RewriteRule ^([A-Za-z0-9\_][A-Za-z0-9\_\-]+)(/)?$ index.php?s=$1 [QSA]
RewriteRule ^spela/(.+)\.html$ /index.php?s=spela&spelet=$1 [QSA,L]
RewriteRule ^fullskarm/(.+)\.html$ /fullskarm.php?spelet=$1 [QSA,L]
RewriteBase /


The original link is always index.php?s="somepage"&dosomethingelse= bla bla
You guys get the point i suppose, feel like an complete idiot...


Best regards, azplund
azplund
 
Posts: 4
Joined: Wed May 20, 2009 9:35 am
Location: Sweden

Postby richardk » Thu May 21, 2009 6:45 am

Code: Select all
Options +FollowSymLinks

RewriteEngine On

# /azplund --> /index.php?s=medlem&v=azplund
RewriteRule ^([a-z_][-a-z_]+)$                  /index.php?s=medlem&v=$1         [NC,QSA,L]
# /azplund/fotoalbum --> /index.php?s=medlem&v=azplund&show=fotoalbum
RewriteRule ^([a-z_][-a-z_]+)/([a-z_][-a-z_]+)$ /index.php?s=medlem&v=$1&show=$2 [NC,QSA,L]


Code: Select all
RewriteRule ^([A-Za-z0-9\_][A-Za-z0-9\_\-]+)/([A-Za-z0-9\_][A-Za-z0-9\_\-]+)$ index.php?s=$1&visa=$2 [QSA,L]
RewriteRule ^([A-Za-z0-9\_][A-Za-z0-9\_\-]+)/([A-Za-z0-9\_][A-Za-z0-9\_\-]+)$ index.php?s=$1&v=$2 [QSA,L]
RewriteRule ^([A-Za-z0-9\_][A-Za-z0-9\_\-]+)/([A-Za-z0-9\_][A-Za-z0-9\_\-]+)$ index.php?s=$1&u=$2 [QSA,L]
RewriteRule ^([A-Za-z0-9\_][A-Za-z0-9\_\-]+)/([A-Za-z0-9\_][A-Za-z0-9\_\-]+)$ index.php?s=medlem&v=$1&show=$2 [QSA]

You can't have more than one rule with the same pattern (regular expression), the first one will always match. You need to make then unique, possibly by adding a prefix.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby azplund » Fri May 22, 2009 5:22 am

richardk wrote:
Code: Select all
Options +FollowSymLinks

RewriteEngine On

# /azplund --> /index.php?s=medlem&v=azplund
RewriteRule ^([a-z_][-a-z_]+)$                  /index.php?s=medlem&v=$1         [NC,QSA,L]
# /azplund/fotoalbum --> /index.php?s=medlem&v=azplund&show=fotoalbum
RewriteRule ^([a-z_][-a-z_]+)/([a-z_][-a-z_]+)$ /index.php?s=medlem&v=$1&show=$2 [NC,QSA,L]



You can't have more than one rule with the same pattern (regular expression), the first one will always match. You need to make then unique, possibly by adding a prefix.



Thank you very much!
Worked like a charm. I will recommend this forum, i no doubt i will continue to use it. Thank you :D
azplund
 
Posts: 4
Joined: Wed May 20, 2009 9:35 am
Location: Sweden


Return to Beginner's Corner

Who is online

Users browsing this forum: No registered users and 118 guests

cron