2012-11-02 27 views
1

我對.htaccess和mod_rewrite很新。我可以使用特定的URL來準備seo友好的網址。不過,我想做一個將統一所有的東西給我。PHP,.htaccess apache統一mod_rewrite只有一個變量

例如;

Original : http://www.domain.com/index.php?module=profile&id=1. 
SEO : http://www.domain.com/profile/1 
.htaccess Code: RewriteRule ^profile/(.*) ?module=profile&id=$1 [L] 

正如你可以看到我有指定profile.htaccess文件中的任何其他模塊的名稱

我想這樣做的是;

Original : http://www.domain.com/?request=module/profile/id/1/other/any 
SEO : http://www.domain.com/module/profile/id/1/other/any 

但是mod_rewrite的相同邏輯不適用。

RewriteRule ^(.*) ?request=$1 [L] 

反正有這個問題嗎?

我完整的.htaccess;

# Disable server signature 
ServerSignature Off 
#################################################################### 
# MOD REWRITE 
#################################################################### 
<IfModule mod_rewrite.c> 
RewriteEngine on 
RewriteBase/

RewriteRule (.*) /index.php?request=$1 [L] 

</IfModule> 

我可以用這種方式沒有任何問題;

# Disable server signature 
ServerSignature Off 
#################################################################### 
# MOD REWRITE 
#################################################################### 
<IfModule mod_rewrite.c> 
RewriteEngine on 
RewriteBase/

RewriteRule ^/ index.php [L] 

RewriteRule ^content/(.*) ?module=content&request=$1 
</IfModule> 

工作版本

# Disable server signature 
ServerSignature Off 
#################################################################### 
# MOD REWRITE 
#################################################################### 
<IfModule mod_rewrite.c> 
RewriteEngine on 

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

RewriteBase/

RewriteRule (.*) index.php?request=$1 [L] 
</IfModule> 

但是我仍然需要指定ATLEAST一兩件事。

謝謝你的幫助。

回答

3

我不明白你們的做法有任何問題,你只需要一個小小的修復:

EDIT 2

RewriteRule (.*) index.php?request=$1 [L] 

就是這樣。順便說一句。您可能只需將所有內容重定向到index.php並在超全局範圍內查找請求參數。

編輯

的問題就在這裏:

<IfModule mod_deflate.c>  <<<<< 
SetOutputFilter DEFLATE 
# Don't compress 
SetEnvIfNoCase Request_URI .(?:gif|jpe?g|png)$ no-gzip dont-vary 
SetEnvIfNoCase Request_URI .(?:exe|t?gz|zip|bz2|sit|rar)$ no-gzip dont-vary 
#Dealing with proxy servers 
<IfModule mod_headers.c>  <<<<< 
Header append Vary User-Agent 
</IfModule> 
</IfModule>      <<<<< 

編輯3個

... 
RewriteEngine on 

# Pass any request not referring directly to a file or directory in the 
# filesystem to index.php  
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule (.*) index.php?request=$1 [L] 
+0

感謝您的快速回復** ** aefxx。但是,我得到這個500內部服務器錯誤。我添加了完整的.htaccess文件。也許我在這個規則之前做錯了什麼。如果你能指出我正確的方向,我會很高興。我寧願不進入超全球,但感謝您的信息。 – Revenant

+0

很可能是最後一個''錯位,請嘗試將它粘貼到#GZIP註釋之前。 – aefxx

+0

我注意到的其他東西:規則'RewriteRule/index.php [L]'是多餘的,因爲這是由** mod_dir **處理的(很可能在開箱即可使用)。相關指令應該閱讀'DirectoryIndex index.php [...]',其中「...」可以是任何你喜歡的作爲後備。 – aefxx