1

I've been looking, at all of the same questions in here like my own: How to rewrite multiple parameters? And figured how to do, but it doesn't seem to work out very well for me.

I wan't my link to look like this: link.dk/profil/2/overview

And my .htaccess looks like this:

#profil.php?id=? to profil/?
RewriteRule ^profil/(.*)$ profil.php?id=$1 [L]
RewriteRule ^profil/(.*)/(.*)$ profil.php?id=$1&do=$2 [L]

It has to be able to access /profil/2 without the 3rd parameter. That's why I have 2 lines. I don't know if this is the right way to do it.

/profil/2 is working perfect and has been working for a while now. So no worries here. But I can't catch the 3rd parameter.

I'm also having those 2 in .htaccess file:

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.php\ HTTP/
RewriteRule ^(.*)index\.php$ /$1 [R=301,L]

RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

Before the first two I wrote.


If I am using just the one with 2 parameters it's working. But then it's not working with /profil/2 ofc. And if I enter the url with profil.php?id=2&do=overview - I can access the page.

0

1 Answer 1

2

Found out my self:

RewriteRule ^profil/([^/]+)$ profil.php?id=$1
RewriteRule ^profil/([^/]+)/([a-z]+)$ profil.php?id=$1&do=$2

.* seems abit unprecise and unstable :-)

Sign up to request clarification or add additional context in comments.

2 Comments

.* is very well defined . "*" is a greedy match -- that is it will match as long as possible. For this type of match, you could use a non-greedy match .*? so for example (.*?)/ means match any charcher sequence, but stop at the first /
alternatively you could change the order of the rules, but your solution is a lot more elegant.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.