Gabriel Silva Gabriel Silva - 1 year ago 53
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
it should be

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]

Answer Source

Try this one (if index.php is in the root folder

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 to 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 ;)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download