0

Here is the result i wanna to achieve:

http://www.sample.com/index.php?sec=fb&h=var2

to

http://www.sample.com/fb?w=var1&var=2

Here is the code from .htaccess file that i tried to use:

RewriteRule ^fb$ fb.php [L]

I would really appreciate if someone taking their time to help me with this question. Many thanks!

henlly
  • 1
  • 1
  • 4

2 Answers2

1

There's no such thing as PHP rewrite. If you want to remove the .php file extension, that can be done.

It's .htaccess rewrite, you could try using this on your .htaccess:

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule !.*\.php$ %{REQUEST_FILENAME}.php [L, QSA]

Also, make sure that you've mod_rewrite on.

First step to do that, is open an SSH connection to your server, login with root and type

a2enmod rewrite

It will enable it for you, or tell that if it's already enabled.

And, make sure that file 000-default located at /etc/apache2/sites-enabled has

<Directory /var/www/>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    allow from all
</Directory>

instead of

<Directory /var/www/>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride None
    Order allow,deny
    allow from all
</Directory>
  • Thanks for your quick reply, I need to correct my question: what i wanna achieve is:http://www.sample.com/index.php?sec=fb&=h=var2 to http://www.sample.com/fb?w=var1&var=2 – henlly Sep 15 '13 at 12:26
  • I can't help with that then, a bit too complicated for me. Why you even want to make a rewrite this complicated? @user2781144 –  Sep 15 '13 at 12:35
  • Sorry if it made you laugh but i have always using this method to create my sites. i guess i will try to do it the way you suggested. Many thanks! – henlly Sep 15 '13 at 12:41
  • @user2781144 It's not SEO friendly, you should stick to clean URLS when possible. –  Sep 15 '13 at 12:51
0

If you want to achieve it for only one url which is http://www.sample.com/fb.php?w=var1&=h=var2

Then use below rewrite rule

RewriteRule ^fb /fb.php [L,QSA]

else if you want for every .php url, Use the above answer by christian

your rewrite rule is fine, just add QSA at the end, to append the query string of the url

Nishant
  • 3,614
  • 1
  • 20
  • 26