2011-11-11 35 views
1

我目前做一個網站(http://tannernelson.me/ehsWordPress的URL參數上GoDaddy的

它託管在Godaddy的,和我使用WordPress作爲CMS。

我希望能夠做:

http://tannernelson.me/ehs/school/academics/teachers/jsmith 

轉成

http://tannernelson.me/ehs/index.php?pagename=teachers&detail=jsmith 

所以,基本上,如果有4段的URL(學校/學者/教師/ JSMITH)我希望最後一個變量。因此,任何URL的第四段將是變量「細節」

我現在的URL重寫目前

# Mod Rewrite 
Options +FollowSymLinks 
RewriteEngine On 
RewriteBase/
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /ehs/index.php [L] 
Options -Multiviews 

這是行不通的任何其他方式,甚至與WordPress默認.htaccess文件。而且我不知道這意味着什麼,或者什麼樣的請求URI被製作出來。這真是令人困惑。

任何想法?

回答

2

你的代碼,現在的意思是:

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

如果請求的文件名!)常規文件-f,如果被請求的文件名!)目錄-d然後:

RewriteRule . /ehs/index.php [L] 

匹配任何單個字符(.),如果匹配發現重寫URL爲/ehs/index.php,然後將其作爲最後一條規則([L]),因此不要處理任何其他規則。

這看起來不像你想要的,但似乎工作。​​服務(我認爲)http://tannernelson.me/ehs/index.php因爲我得到一個自定義的404找不到頁面。

請嘗試以下.htaccess代碼:

Options +FollowSymLinks 
RewriteEngine On 
RewriteBase/

# Redirect the ehs/school/academics/$1/$2 URIs to /ehs/index.php?pagename=$1&detail=$2 
RewriteRule ^ehs/school/academics/([^/]+)/([^/]+)$ /ehs/index.php?pagename=$1&detail=$2 [L] 

# Otherwise if the requested URI is not found (not a file nor a directory) 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 

#Redirect everything else to index.php 
RewriteRule .* /ehs/index.php [L] 

Options -Multiviews 

我只是測試這是我的Apache服務器和它的作品。