2015-07-20 37 views
1

我寫我的.htaccess文件與htaccess的工作 - 網頁沒有被正確加載

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] 

我認爲這個問題在下面的行發生在下面的代碼:

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

基本上我想,當用戶類型searchPage.php?crs_category=business 它將url重寫爲category/businesscategory/business/category/BUSinesS/category/BUsineSS

因爲它代表了以下問題此行是如下:

  1. 的CSS/JS似乎加載
  2. 它只有當我鍵入類/業務/如果我鍵入searchPage.php工作?crs_category =業務並不重定向或重寫,以乾淨的URL
+0

重寫[R ule將無法爲你做到這一點。使用JavaScript,看看這裏http://stackoverflow.com/questions/3338642/updating-address-bar-with-new-url-without-hash-or-reloading-the-page – Jigar

回答

1

試試這個:

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] 
+0

謝謝你的答案,和建議,儘管有兩件事:在本地主機上重寫似乎將其重寫爲http:// localhost/opt/lampp/htdocs/website/category/Web%2520development默認情況下爲localhost/website /,並且我鍵入localhost/website/searchPage.php?category = business第二個問題是由於某些原因,當url重寫完成後,relvant css/js文件未加載 – John

+0

取消註釋或添加RewriteBase /行,並解決js和css問題,您可以 更改頁面標題中的URI基礎(在''標記之間,添加 ''' – starkeen