HTACCESS友好的网址,参数为2

时间:2014-08-18 07:55:00

标签: php apache .htaccess mod-rewrite redirect

我有点问题。

从.htaccess重定向:

domena.pl/index.php?galeria

domena.pl/galeria

工作正常,但现在我需要重定向

domena.pl/index.php?galeria=Inne

domena.pl/galeria/inne

也给了我重定向循环。

我的.htaccess现在是:

RewriteEngine On  
RewriteBase /

RewriteCond %{HTTP_HOST} ^domena.pl(.*) [NC]  
RewriteRule ^(.*)$ http://www.domena.pl/$1 [R=301,L]

RewriteCond %{THE_REQUEST} \s/+index\.php\?([^\s=]+?)\s [NC]
RewriteRule ^ /%1? [R=301,L,NE]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z-]+)$ index.php?$1 [L,QSA] 

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z]+)/([a-z-]+)$ index.php?$1=$2

1 个答案:

答案 0 :(得分:2)

以下是我在网站上所做的一个示例:

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

# external redirect from /view.php?id=1 to /view/id/1
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+([^.]+)\.php\?([^=]+)=([^\s&]+) [NC]
RewriteRule ^ /%1/%2/%3? [L,R=301]

# internal forward from /view/id/1 to /view.php?id=1
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/?$ /$1.php?$2=$3 [L,QSA]