2013-03-20 50 views
2

我目前在Kirby中建立了一個畫廊,並且有一個相冊頁面,有效地有兩種模式:1)畫廊列表,顯示所有項目。 2)單個圖像。我傳遞一個GET變量,像這樣:kirby .htaceess和GET變量

/gallery/album-name?p=03.jpg 

我真正想要的是像這樣的URL:

/gallery/album-name/03.jpg 

科比已經做了一些網址在其默認.htaccess文件重寫,像這樣:

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*) index.php [L] 

從這個/index.php/gallery/album-name?p=03.jpg取出index.php部分重新寫入網址。現在

,當時我認爲我可以簡單地重寫它有這樣一個GET變量的任何網址:

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)/([A-Za-z0-9-]+)?$ index.php?p=$1 [L] 

但是,這似乎並沒有工作。

我的問題是:這可以做到嗎?如果是這樣,GET變量仍然可用於我的腳本?

非常感謝!


我現在完全重新編寫規則

<IfModule mod_rewrite.c> 

RewriteEngine on 
RewriteBase/

#//www. vs // 
RewriteCond %{HTTPS} !=on 
    RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC] 
    RewriteRule^http://%1%{REQUEST_URI} [R=301,L] 

# block text files in the content folder from being accessed directly 
RewriteRule ^content/(.*)\.(txt|md|mdown)$ error [R=301,L] 

# block all files in the site folder from being accessed directly 
RewriteRule ^site/(.*) error [R=301,L] 

# block all files in the kirby folder from being accessed directly 
RewriteRule ^kirby/(.*) error [R=301,L] 

# make panel links work 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^panel/(.*) panel/index.php [L] 

# make gallery links work 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^gallery/(.*)/([A-Za-z0-9-]+\.jpg)?$ index.php?p=$2 [L] 

# make site links work 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*) index.php [L] 

</IfModule> 

這適用於一切,但我得到(例如)這個網址404:/gallery/my-gallery-name/01.jpg

+0

我建議你不要改變重寫規則,而是使用PARAMS功能與未來柯比:http://getkirby.com/blog/the-mighty-mighty-uri-object – lulezi 2013-06-24 20:24:18

回答

1

試試這個,它會工作

RewriteRule ^our-wedding/(.*)$ index.php?p=$1 [L] 

現在,您可以通過

訪問3210
/gallery/our-wedding/03.jpg 
+0

謝謝,但是'URL'的/ our-wedding /部分已經被.htaccess重寫了。基本URL如下所示:'mysite.com/index.php/gallery/our-wedding/?p = 01.jpg'。也有許多畫廊。 – 2013-03-20 19:04:38

+0

我想用這種方法,我不得不添加一個規則,每次我添加一個畫廊。 – 2013-03-20 19:10:43

0

RewriteRule有兩個regular expression部分

^(.*)/([A-Za-z0-9-]+)?$ 
    | | 
    $1 $2 

$1是畫廊部分,$2是可選的圖片部分。 無論您需要什麼,您只能使用其中一個或兩個部分。如果您希望只使用圖片的一部分,你必須在你的重寫規則

RewriteRule ^(.*)/([A-Za-z0-9-]+)?$ index.php?p=$2 [L] 

雖然使用$2,你的圖像部分的正則表達式不比賽03.jpg。如果你想匹配的是,您必須在字符類[...].或擴展添加到它

[A-Za-z0-9-]+\.jpg 
+0

謝謝你,但我仍然無法得到的東西工作。我使用'^ gallery'來匹配,因爲使用'^(。*)'意味着我的網站周圍的其他鏈接停止工作了(比如'/ about'等等)...我在問題中粘貼了全部重寫規則。 – 2013-03-21 00:09:03

+0

@JonRoobottom這應該工作。你有根目錄中的'index.php'嗎? – 2013-03-21 07:33:58

+0

是的。我不知道[柯比](http://getkirby.com)是否正在做其他任何時髦的東西。我上面發佈了完整的.htacccesss重寫規則,也許這裏有一些衝突?謝謝! – 2013-03-21 09:12:35