2012-04-24 52 views
1

我試圖找出如何做這樣的事情在htaccess的網址:htaccess的重定向包含的東西

#This address links to a place that does not exist 
localhost/prefix/games/userid/game-name 

默默地([L],我猜)重定向到

#This folder has an index.php, so we're good! 
localhost/prefix/protected/files/userid/game-name/ 

我知道我可以有一個鏈接:

localhost/prefix/games/index.php?user=userid&title=game-name 

,只是有在index.php有一定重定向投放...

但我不希望網址參數在我的網站上的鏈接中可見 ...所以我想它確實需要是htaccess。

我不得不承認,我讀了htaccess的東西,它正好在我頭上,因爲沒有人用我理解的方式解釋。

任何幫助將不勝感激。

編輯:: ///

RewriteEngine On   
RewriteBase /prefix 

# stop directory listings 
Options -Indexes 

#stops htaccess views 
<Files .htaccess> 
order allow,deny 
deny from all 
</Files> 

# remove .php; use THE_REQUEST to prevent infinite loops 
    RewriteCond %{THE_REQUEST} ^GET\ (.*)\.php\ HTTP 
    RewriteRule (.*)\.php$ $1 [R=301]   

# remove index 
    RewriteRule (.*)/index$ $1/ [R=301] 

# remove slash if not directory 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteCond %{REQUEST_URI} /$ 
    RewriteRule (.*)/ $1 [R=301] 

# add .php to access file, but don't redirect 
    RewriteCond %{REQUEST_FILENAME}.php -f 
    RewriteCond %{REQUEST_URI} !/$ 
    RewriteRule (.*) $1\.php [L]  

# redirect game folders 
    RewriteRule ^prefix/games/(.*)$ /prefix/protected/files/$1/ [R=301] 

回答

0

你可以有

RewriteRule ^prefix/games/(.*)$ prefix/protected/files/$1 [L] 

所有http://localhost/prefix/games/userid/game-name鏈接重定向到http://localhost/prefix/protected/files/userid/game-name

或者,你可以有

RewriteCond %{QUERY_STRING} user=(.*)&title=(.*)$ 
RewriteRule ^prefix/games/index.php$ /prefix/protected/files/%1/%2? [L] 

移動像所有鏈接:http://localhost/prefix/games/index.php?user=userid&title=game-namehttp://localhost/prefix/protected/files/userid/game-name

+0

看一下第一種:(。*) ^ =主機/域,=這部分變量存儲,$撥打變量集? – Jimmyt1988 2012-04-24 22:58:23

+0

'''=>在域之後開始,剩下的兩個假設是正確的。 – hjpotter92 2012-04-24 23:01:22

+0

您好,先生,非常有幫助。我會盡力嘗試自己做下一個。蜱! – Jimmyt1988 2012-04-24 23:02:12

相關問題