Re-write url with htaccess

Asked

Viewed 73 times

1

For lack of experience, I’m having difficulty rewriting my blog url, I tried as below:

http://www.meusite.com/blog/article.php?a=3&v=5&at=teste-do-primeiro-post

In the end I would like the result below:

http://www.meusite.com/blog/article/teste-do-primeiro-post

I put the .htaccess at the root and then inside the blog folder, which folder .htaccess has to stay?

My last attempt below:

RewriteEngine on

RewriteRule ^article/([0-9]+)/([0-9a-zA-Z_-]+) article.php?a=$1&v=$1&at=$1 [NC,L]

1 answer

0

The problem is in regular expression!

For example, you’re picking numbers with the ER ([0-9]+) in the place where he would come teste-do-primeiro-post, which is a sequence of characters.

Generally speaking, without restriction other than /, you can try the below (I put one more at2 variable besides yours that gets the rest of the URL - until the end):

RewriteRule ^([^\/]*)\/?([^\/]*)\/?([^\/]*)\/?(.*)$ article.php?a=$1&v=$2&at=$3&at2=$4 [L,QSA]
  • I inserted in the main folder of the server this way Rewriterule ^?([^/])/?([^/])/?([^/])/?(.)$ article.php? a=$1&v=$2&at=$3 [L,QSA] and generated the Internal error 500

  • You have to insert into the "blog" folder, where it contains the article folder!

  • I inserted inside the blog folder, but is returning error 500

  • I removed the first ? was wrong in the answer. You can try to put the path forward (after the ^) or tb use the RewriteBase / or RewriteBase /blog/

Browser other questions tagged

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