2015-05-18 169 views
1

我想從我的URL中刪除獲取密鑰。htaccess從url中刪除參數名稱

因此https://www.website.com/?page=gallery會變成https://www.website.com/gallery

如果&action在那裏,它應該像 https://www.website.com/?page=gallery&action=viewhttps://www.website.com/gallery/view

當然,galleryview是動態的 - 它們定義了我的網站加載的頁面。

我一直在嘗試整天,但無濟於事。你們能幫助我嗎?

我目前.htaccess

Order Allow,Deny 
Allow from <MYIP> 

ErrorDocument 403 /message.html 

Options +FollowSymLinks -MultiViews 
# Turn mod_rewrite on 
RewriteEngine On 
RewriteBase/

#Hide index.php 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ index.php?$1 [L,QSA] 
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s(.*)/index\.php [NC] 
RewriteRule^%1 [R=301,L] 


#Force www and https: 
RewriteEngine on 
RewriteCond %{HTTP_HOST} ^website.com [NC] 
RewriteRule ^(.*)$ https://www.website.com/$1 [L,R=301,NC] 

#Gzip 
<ifmodule mod_deflate.c> 
    AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript text/javascript 
</ifmodule> 
#End Gzip 

Options -Indexes 

回答

1

給下面的一個嘗試(剛剛超過你的gzip部分):

# Step 1: Redirect query-based URL to new one 

RewriteCond %{QUERY_STRING} ^page=([^&\s]+)$ 
RewriteRule ^(?:index\.php|)$ /%1? [R=301,L] 

RewriteCond %{QUERY_STRING} ^page=([^&\s]+)&action=([^&\s]+)$ 
RewriteRule ^(?:index\.php|)$ /%1/%2? [R=301,L] 

# Step 2: Rewrite new URIs to query-based one 
# 
# Note how a dummy &r is used in the destination - this is 
# to prevent infinite loops 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^([^\s\/]+)/?$ index.php?page=$1&r [L,QSA] 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^([^\s\/]+)/([^\s\/]+)/?$ index.php?page=$1&action=$2&r [L,QSA] 
+0

謝謝你,這工作。 :)可能需要修復的最後一部分是&action =它加載頁面?page = page&action = ACTION。然而它幾乎完美的工作!這東西很混亂,但我真的很喜歡它。關於接下來要做什麼的任何想法? –

+0

不客氣。它不應該這樣做,因爲'%2'後面的問號會取消查詢字符串。也許嘗試清除緩存? –

+0

我不確定,即使在清除緩存後仍然如此。 –

0

你可以嘗試使用QUERY_STRING狀態 - 也許是這樣的:

RewriteCond %{QUERY_STRING} ^page=(.*)$ 
RewriteRule ^(.*)$ /%1/ [R=301,L] 

RewriteCond %{QUERY_STRING} ^page=(.*)&action=(.*)$ 
RewriteRule ^(.*)$ /%1/%2/ [R=301,L] 
0

沒有測試過這一點,但根據你的要求是什麼東西像這樣應該會讓你在那裏?:

RewriteEngine on 
# to convert from folders request query string index handler 
RewriteRule ^/([^/\.]+)(/([^/\.]+))/?$ index.php?page=$1&action=$3 [L] 
# or reverse from query string to folder paths (more limited/confining) 
RewriteRule ^/?(page=([^&]+)(&action=([^&]+)(&?(.*))$ /$2/$4?$6 [L] 
+0

'mod_rewrite'不支持查詢字符串的規則。發佈答案前請閱讀文檔。 –

0

嘗試添加這是低力WWW規則:

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/(?:index\.php|)\?page=([^&\ ]+) 
RewriteRule^/%1? [L,R] 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ /?page=$1 [L,QSA] 
+0

這是迄今爲止工作最多的。 https://www.website.com/gallery/?page=gallery是結果 –

+0

@AustinWilley您確定您在規則目標的末尾添加了?? –