Gabriel Silva Gabriel Silva - 2 months ago 8
PHP Question

.htaccess not working with php includes

I'm trying do use mod_rewrite at my .htaccess but isn't working.

my url is http://gestor.samfbas.com.br/index.php?p=something
it should be http://gestor.samfbas.com.br/something

The file is in a subdirectory (gestor) in my host, where all the files are.

<IfModule mod_rewrite.c>
Options +FollowSymLinks +Indexes
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/?$ /index.php?p=$1 [L]
</IfModule>

Answer

Try this one (if index.php is in the root folder http://gestor.samfbas.com.br/index.php):

Options +FollowSymLinks
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/index.php
RewriteRule ^(.*)$ index.php?p=$1 [L,QSA]

This should work. Testet it here on my local maschine (No other server redirects or else, just a fresh xampp installation).

It redirect http://gestor.samfbas.com.br/something to http://gestor.samfbas.com.br/index.php?p=something without changing the url in the browser.

And additional to the question in the comment. This URL part p= should not be known be outside users! Better use a long var here like sadff34dngn4nil212ugn=, so nobody can call the index.php with parameters directly from outside. You can't prevent that 100% but the redirect parameter p= is only for internal use.

But its just my opinion on that.

Hopefully that helps a little.

Find the right way to rome ;)