Rule for parameter redirection

0

I'm trying to set up a friendly URL system, but I have the following problem:

I have a page that has a list with multiple items. The page has this URL:

http://localhost/personal/portifolio

When the user accesses one of these items, he is redirected to:

http://localhost/personal/projeto?id=2

I would like the URL to look like this:

http://localhost/personal/projeto/nome-do-projeto

I have URL rules that work fine, but this is not working:

#codigo produtos não funciona    
RewriteEngine on
RewriteCond %{QUERY_STRING} != ""
RewriteCond %{QUERY_STRING} ^id=[(0-9)]$
RewriteRule ^projeto/[(a-zA-Z0-9)+]/[(0-9)+]/?$ /projeto?id=$2&title=$1 [NC]

The parameter is thus passed:

<a href='".$_url."projeto?id=".$portifolio['id']."&tittle=".$portifolio['tittle']."'>'

in $_url has http://localhost/personal/ .

    
asked by anonymous 06.03.2016 / 19:27

2 answers

0

After studying a few weeks regular expressions, I got:

RewriteEngine On
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^projeto/(.*)$ projeto.php?$1

and href I go like this:
<a href='".$_url."projeto?".$portifolio['tittle']."'>

Only problem is that it has a ? there in the middle, it works if I put / but in the page it does not load the images ... I need to change the path from ./ to ../ if someone can complement appreciate! =)

    
13.03.2016 / 18:45
2

It's been a long time since I've used Apache's rewrite rules, but in your rule you're setting up the URL with id and title, but the URL you'd like to get only has the title, so your rule is only can have the title to work.

Another thing is that the title has an extra "t" in your HTML. Also the string concatenation operator was used in the wrong way.

And when you access the URL should be the final URL and not with the parameters, that is, instead of

<a href='".$url."projeto?id=".$portifolio['id']."&tittle=".$portifolio['title']."'>

would be

<a href="$url" . 'projeto/' . $portifolio['title']>
    
07.03.2016 / 02:57