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