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...

2

5 Answers 5

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" .

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

Comments

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

Comments

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.

3 Comments

no RewriteRule ^.*/(.*)\.html?$ index.php?page=$1 [L,QSA] is not working in my website ... facing same problem yet..
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.
when i click on any link which use rewrite rule then server give me error 404 File or directory not find..
1

Try:

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

Comments

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!

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.