1

I have the following code written in my .htaccess document

RewriteEngine On


# If you need to use the `RewriteBase` directive, it should be the
# absolute physical path to the directory that contains this htaccess file.
#
# RewriteBase /

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


RewriteRule ^category/([a-z]+)/?$ searchPage.php?crs_category=$1

RewriteRule ^ index.php [QSA,L]

the problem I think occurs in the following line:

RewriteRule ^category/([a-z]+)/?$ searchPage.php?crs_category=$1

Essentially I want when a user type searchPage.php?crs_category=business it rewrite the url to category/business or category/business/ or category/BUSinesS/ or category/BUsineSS

As it stands the following problems with this line is as follow:

  1. the css/js seems to load
  2. it only works when i type category/business/ if i type searchPage.php?crs_category=business it does not redirect or rewrite to the clean URL
code_legend
  • 3,547
  • 15
  • 51
  • 95
  • rewrite rule won't be able to do that for you. use javascript, have a look here http://stackoverflow.com/questions/3338642/updating-address-bar-with-new-url-without-hash-or-reloading-the-page – Jigar Jul 20 '15 at 17:04

1 Answers1

1

Try this :

RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} /searchPage.php\?crs_category=([^\s]+) [NC] 
RewriteRule ^ category/%1? [NE,NC,R,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^category/([^/]+)/?$  searchPage.php?crs_category=$1 [QSA,L,NC]
Amit Verma
  • 40,709
  • 21
  • 93
  • 115
  • thank you for you answer, and suggestion, though two things: on local host the rewrite seems to rewrite it as such http://localhost/opt/lampp/htdocs/website/category/Web%2520development where at default it was localhost/website/ and i type localhost/website/searchPage.php?category=business the second issue is for some reason the relvant css/js files are not loaded when url rewrite is done – code_legend Jul 20 '15 at 17:03
  • Uncomment or add the RewriteBase / line , and to solve js a nd css issue you can change the URI base in the header of your pages (inbetween the ` ` tags ,add `` – Amit Verma Jul 20 '15 at 17:07