1

i've a little problem with Apache mod rewrite configuration.

I need to have an url like this:

http://mysite.com/search+terms

I've tried this config in htaccess but it does not work:

RewriteRule ^(.*)$ /search.php?s=$1

It return to me an 500 Internal Server Error.

How I can fix it? Thank you.

cathulhu
  • 641
  • 1
  • 9
  • 20
Mirko
  • 165
  • 2
  • 12

3 Answers3

0

Try to put this lines,

RewriteEngine on
RewriteBase /

and also set the RewriteBase to correct location of search.php

Edit

I can categorize it as duplicate to htaccess rewrite for query string

Edit 2

Remove the prefix slash on

RewriteRule ^(.*)$ /search.php?s=$1

to become

RewriteRule ^(.*)$ search.php?s=$1
Community
  • 1
  • 1
ardhitama
  • 1,949
  • 2
  • 18
  • 29
  • Ok, the search.php is in the root directory and the error 500 is shown for all pages of the site (not just when I try to make a search through the new url). Thank you – Mirko Jul 16 '13 at 08:27
  • could you post the full .htaccess? – ardhitama Jul 16 '13 at 08:28
  • Sure `RewriteEngine On RewriteBase / RewriteRule ^(.*)$ /search.php?s=$1 [L]` – Mirko Jul 16 '13 at 08:30
  • well, the problem is this condition ^(.*)$ make all your request to search.php, including index.php request. I suggest make the rule like this `RewriteRule ^(.*)$ /index.php?s=$1` but i dont know how your structure are, so I'm just guessing here – ardhitama Jul 16 '13 at 08:44
  • also check this http://stackoverflow.com/questions/1231067/htaccess-rewrite-for-query-string – ardhitama Jul 16 '13 at 08:46
  • Ok, i've integrated search.php in index.php and if I go in http://example.com/index.php?s=search+terms it works fine, but if I use a rewrite rule like `RewriteRule ^(.*)$ /index.php?s=$1` it still return me back to `error 500`. I've followed your link but it contain the same rules that i've insert in my htaccess file – Mirko Jul 16 '13 at 09:42
  • this is silly, but try this: `RewriteRule ^(.*)$ index.php?s=$1` notice that i've removed the slash – ardhitama Jul 16 '13 at 10:20
  • Uhm but now all the other pages not work (like css etc) and the homepage go on the search results – Mirko Jul 16 '13 at 10:26
  • add this RewriteCond %{REQUEST_FILENAME} !-f check @anubhava answer, he gives you the complete rule – ardhitama Jul 16 '13 at 10:30
0

Try this .htaccess code :

RewriteEngine on
RewriteRule ^search+(.*)$ /search.php?s=$1
Lucas Willems
  • 6,673
  • 4
  • 28
  • 45
0

You're getting 500 internal error because of infinite looping since your regex .* is always matching even after rewrite. You need to stop this using a RewriteCond. Replace your code with this:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ search.php?s=$1 [L,QSA,NE]
anubhava
  • 761,203
  • 64
  • 569
  • 643