htaccess returns $i

Asked

Viewed 35 times

0

Good evening, I made a code htacces like this:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteRule ^app/([0-9]+) app.php?id=$i

The first Rule is to take the ". php" of the pages and the second is so that instead of appearing app.php? id=11 appear app/11, but when I do $_GET["id"]; it returns "$i" which is the htaccess variable, someone knows the solution so that it returns the id value, in this case, I’m using alphanumeric ids, for example: 09a6cc

Thanks in advance.

  • 1

    In case I believe that to capture the first group of regex, it would be $1 and not $i

1 answer

1

Switch to that:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteRule ^app/(.*)$ app.php?id=$1

In this case, you put $i instead of $1. And also, this allows alphanumerics.

  • It worked, but the pages that are without the . php stopped working, I believe that the code Rewriterule (.*)$ $1.php is to do this, but here it didn’t work, you can tell me why?

  • And using exactly your code without changing, it returns in $_GET["id"] this: 18ceb3.php/18ceb3, and 18ceb3 is the url id.

  • I changed my answer. I had accidentally put to rewrite the page as well. Try now

  • Not to be annoying, but already being, like, you’re helping a lot, but now with this fix you made, the link without the . php work, but in the app, making $_GET["id"] it returns the page id along with . php Example: e1d166.php being e1d166 the page id.

Browser other questions tagged

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