2

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>
9
  • Please add some more information to this, I'm having a hard time finding out what the issue really is. Commented Sep 15, 2016 at 13:17
  • What do you mean with my url is? Did you put that on your html page? And this http://gestor.samfbas.com.br/index.php?p=something will not redirected because the condition RewriteCond %{REQUEST_FILENAME} !-f fails here, and this http://gestor.samfbas.com.br/something seems to be working Commented Sep 15, 2016 at 13:19
  • READ THIS: I can see your directories gestor.samfbas.com.br/scripts secure your server remove Options +Indexes Commented Sep 15, 2016 at 13:29
  • @JustOnUnderMillions I removed it, thanks! Commented Sep 15, 2016 at 14:00
  • @JustOnUnderMillions my home page is gestor.samfbas.com.br/index.php. When I redirect to some page I use the condition ?p=something but my url doesn't rewrite to /something. Commented Sep 15, 2016 at 14:01

1 Answer 1

0

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

Sign up to request clarification or add additional context in comments.

8 Comments

And if I have something/page/1, how it works? my url is gestor.samfbas.com.br/?p=users&page=2 it should be gestor.samfbas.com.br/users/page/2
@Gabriel Silva Currently, if you use it like above, it will redirect to index.php?p=something/page/1 the rest can be done and normally is done in PHP.
Yeah and gestor.samfbas.com.br/users/page/2 becomes finally gestor.samfbas.com.br/index.php?p=users/page/2 and this is the first step to make an dynamic framework :)
May the problem is that you currently have this gestor.samfbas.com.br/?p=users&page=2 generated by php but you want this gestor.samfbas.com.br/users/page/2, OK, but this is a new question for Stackoverflow. Tip str_replace(array('=','&'),'/','?p=users&page=2') and the remove the rest...
I don't get it =( gestor.samfbas.com.br/users/page/2 should redirect to gestor.samfbas.com.br/index.php?p=users&page=2 What should I do?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.