htaccess从url中删除param名称

时间:2015-05-18 03:10:29

标签: php .htaccess

我正在尝试从我的网址中删除获取密钥。

因此https://www.website.com/?page=gallery将成为https://www.website.com/gallery

如果&action存在,那应该是这样的 https://www.website.com/?page=gallery&action=view https://www.website.com/gallery/view。{/ p>

当然,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

4 个答案:

答案 0 :(得分: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]

答案 1 :(得分:0)

您可以尝试使用QUERY_STRING条件 - 可能是这样的:

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

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

答案 2 :(得分: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]

答案 3 :(得分:0)

尝试在强制www规则下面添加以下内容:

Func