0

i am trying to create an .htaccess file that will achieve the following

  1. create a clean url like this www.mydomain.com/About-Us with page page.php?title=About Us
  2. query a database with the parameters passed on the url like this www.mydomain.com/?search=abc and it pulls to page index.php?search=abc

this is my code so far

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^?search=([0-9]*)$ index.php?id=$1 ## e.g www.mydomain.com/?search=try
RewriteRule ^([A-Z]*)$ page.php?name=$1 
## www.mydomain.com/About-Us

##ErrorDocument 404 PageNotavailabale


####Protect the system from machines with worms
RewriteRule (cmd|root)\.exe - [F,E=dontlog:1]

#### To hold and redirect css/images/js files
RewriteRule images/(.+)?$ images/$1 [NC,L]
RewriteRule css/(.+)?$ css/$1 [NC,L]
RewriteRule js/(.+)?$ js/$1 [NC,L]

1 Answer 1

3

Why not using this kind of url for your search engine : www.domain.com/search/abc ?

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^search/([a-zA-Z0-9]+)$   index.php?search=$1
RewriteRule ^([a-zA-Z0-9]+)$          index.php?page=$1 

Then, your access your pages with www.domain.com/<myPage>.

And your search engine with www.domain.com/search/<mySearch>

EDIT :

Please notice your rules doesn't allow a lot of params :

  • ^?search=([0-9]*)$ allows only numbers (even an empty parameter)
  • ^([A-Z]*)$ allows only uppercase letters (and also empty parameter)
Sign up to request clarification or add additional context in comments.

Comments

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.