.htaccess URL friendly PHP problem

Asked

Viewed 429 times

0

I have a link like this:

<a href="index/pagina=$i"> $i </a>

wanted the URL to look like this:

index/2

and I’m using the .htaccess thus:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^index?$ index.php [NC,L]
RewriteRule ^index/([a-z0-9-]+)/?$ index.php?pagina=$1 [NC]
</IfModule>

Where is the problem?

1 answer

0


It seems that the problem is in href of your a. The .htaccess is correct but the link you are printing is not.

It should be like this (to generate index/$i)

<a href="index/$i"> $i </a>
  • It redirects but the css comes back all broken

  • @Brendollourençon Add <base href="http://[SEU SITE]/" /> in the head from your page and see if it solves your problem.

  • in the <base href="http://localhost case/" /> ?

  • Man I don’t know how to thank you, it worked out here Andre Brook thank you so much !

  • about "broken css", just add two exceptions in htaccess. This prevents you from applying the rules to existing files physically Rewritecond %{SCRIPT_FILENAME} ! -f This other for directories: Rewritecond %{SCRIPT_FILENAME} ! -d Hence you don’t even need to use the <base tag>

  • I will post separately because there is no line break in the comments

  • with the <base href="http://[YOUR SITE]/" /> worked, I did not know this tag, got it right, thanks ai galera !

  • Rewritecond %{SCRIPT_FILENAME} ! -f

  • Rewritecond %{SCRIPT_FILENAME} ! -d

Show 4 more comments

Browser other questions tagged

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