0

I use this htaccess url mywebsite.com/xyz/search.html

here xyz is a folder in root

in .htaccess is use the code for this url

# enable apache modRewrite module #
RewriteEngine On

RewriteBase /

RewriteRule ^([^//]+)/?(^/*)?.ht(m?ml?)$ index.php?page=$1 [L,QSA]

now i want this xyz/search.html is hit the url xyz/index.php?page=search

but this:

RewriteRule ^([^//]+)/?(^/*)?.ht(m?ml?)$ index.php?page=$1 [L,QSA])

code is not working.. any idea regarding this...

SuReSh
  • 1,503
  • 1
  • 22
  • 47

5 Answers5

12

Type some random characters in your .htaccess file and try to reload your page, if you see error 500 then your .htaccess file is working, put your random characters after "RewriteEngine On" .

Ankur Patel
  • 129
  • 1
  • 3
2

Not sure that rule would work. Does this one do the job?

RewriteRule ^.*/(.*)\.html?$ index.php?page=$1 [L,QSA]

Also, if you want to test the rule with a bit more visibility, you can add R=302 to the flags, that way your browser will get a redirect and you'll be able to see the rewritten URL in the address bar

arco444
  • 22,002
  • 12
  • 63
  • 67
1

I wonder why people don't use RewriteLog.

Put in the same place:

RewriteLog /tmp/rewrite.log
RewriteLogLevel 3

It slows down the server but for debugging it's made for.

Daniel W.
  • 31,164
  • 13
  • 93
  • 151
  • no RewriteRule ^.*/(.*)\.html?$ index.php?page=$1 [L,QSA] is not working in my website ... facing same problem yet.. – SuReSh Aug 05 '14 at 12:36
  • please tell me first how i know my .htaccess file is working or not.. acc. to my knowledge my .htaccess file code is fine. is this a server problem? because of in main server .htaccess file is working but in demo server it not working. – SuReSh Aug 05 '14 at 12:37
  • when i click on any link which use rewrite rule then server give me error 404 File or directory not find.. – SuReSh Aug 05 '14 at 12:43
1

Try:

RewriteEngine On
RewriteBase /
RewriteRule ^(.*?)/?([^/]+)\.ht(m|ml)?$ $1/index.php?page=$2 [L,QSA]
Jon Lin
  • 142,182
  • 29
  • 220
  • 220
1

There is a very handy online tool for testing htaccess files. Simply paste your redicrect rules in the form provided and test various urls to see if they are redirected or left untouched.... soooper easy!

Aurovrata
  • 2,000
  • 27
  • 45