2014-12-30 70 views
1

很抱歉,如果我不好解釋我的問題,這是一個有點難以解釋什麼錯*
我已經與.htaccess文件玩弄現在有一段時間,試圖讓這個工作。
我有以下的文件在我的網站目錄:的.htaccess URL重寫GET參數,並刪除.PHP沒有打破的JavaScript/CSS

- index.php 
- generator.php 
- menu.php 
- gift-history.php 
- stats.php 

- images/ 
    - bg-stars.png 
    - avatar.png 

- css/ 
    - style.css 
    - glow.css 
    - background.css 

- js/ 
    - script.js 
    - jquery.js 
    - destiny.js 
    - snowflake.js 

這三個文件夾是images,css and js
該generator.php需要一個$_GET paremeter知道什麼發電機加載。
到目前爲止,我一直在使用以下網址:
http://tryhardhusky.com/generator.php?t=destiny
對於其他的網頁,我在我的.htaccess文件下面的代碼:

php_value display_errors Off 
php_flag magic_quotes 1 
php_flag magic_quotes_gpc 1 
php_value mbstring.http_input auto 
php_value date.timezone America/New_York 
Options +FollowSymLinks -MultiViews 
# Turn mod_rewrite on 
RewriteEngine On 
RewriteBase/
## hide .php extension snippet 
# To externally redirect /dir/foo.php to /dir/foo 
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC] 
RewriteRule^%1 [R,L] 
# To internally forward /dir/foo to /dir/foo.php 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}.php -f 
RewriteRule ^(.*?)/?$ $1.php [L] 

這幾乎將刪除該.php擴展文件名,那麼文件將是:
http://tryhardhusky.com/gift-history.php
變爲:
http://tryhardhusky.com/gift-history

我試圖進入以下頁面:
http://tryhardhusky.com/generator.php?t=destiny
改寫爲
http://tryhardhusky.com/generator/destiny

我以前所有的嘗試都打破了js和css,加載頁面(儘管位置時返回404錯誤正確)
[錯誤404未找到:http://tryhardhusky.com/js/jquery.js]

任何線索我怎麼能做到這一點,而不會破壞它?

回答

1

您可以通過這一個在您的htaccess

Options +FollowSymLinks -MultiViews 

RewriteEngine On 
RewriteBase/

# rewrite /generator.php?t=XXX to /generator/XXX 
RewriteCond %{THE_REQUEST} \s/generator\.php\?t=([^\s&]+)\s [NC] 
RewriteRule^generator/%1? [R=301,L] 

# hide PHP extension for existing files 
RewriteCond %{THE_REQUEST} \s/(.+?)\.php(?:\s|\?) [NC] 
RewriteCond %{REQUEST_FILENAME} -f 
RewriteRule^%1? [R=301,L] 

# internally rewrite /generator/XXX to /generator.php?t=XXX 
RewriteRule ^generator/([^/]+)$ generator.php?t=$1 [L] 

# internally rewrite to PHP file extension (if existing) 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}\.php -f 
RewriteRule ^(.+)$ $1.php [L] 
+0

這重寫URL我想要的方式替換當前的代碼,但現在我得到一個'無法加載資源:服務器與迴應狀態500(內部服務器錯誤)'嘗試加載時出錯tryhardhusky.com/js/jquery.js – Kain

+1

對於哪個網址你有這個錯誤?哪個目標文件?這當然來自相對路徑(您應該使用絕對路徑) –

+0

目標文件是'http:// tryhardhusky.com/js/jquery.js' – Kain