Rule for redirecting with parameters

Asked

Viewed 294 times

0

I’m trying to build a friendly URL system but I’m having the following problem:

I have a page that has a list of several items. The page has this URL:

http://localhost/personal/portifolio

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

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

I’d like the URL to look like this:

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

I have rules of Urls that work well, 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 passed like this:

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

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

  • Hebert, if you can, take a peek at the editing history, to see how to format a post. Here’s some more advanced help: http://answall.com/editing-help

2 answers

2

It’s been a long time since I’ve used Apache rewriting rules, but in your rule you’re mounting the URL with id and title, but the URL you’d like to get just has the title, so your rule can also only have the title to work.

Another thing is that the title has an extra "t" in its HTML. Also the string concatenation operator has been misused.

And when you access the URL should be the definitive 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']>
  • I wrote even so for difference from attribute title html, that tittle is because it comes from the rs bank, but to use this url, as it happens to be the .htaccess?

  • Have you ever tried to leave only the title part in the rule, as I suggested?

  • yes I had tried, error 500 =/

0


after studying a few weeks regular expressions, I managed to:

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

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

only problem is, that has a ? in the middle there, it works if I put / but the page does not load the images... I need to change the path of ./ for ../if anyone can supplement thank you! =)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.