如何使用.htaccess重写此URL

时间:2012-03-27 08:28:23

标签: regex apache .htaccess mod-rewrite

如何重写此网址

  

http://staging.felgenexklusiv.de/?felge=asa-gt1

这样显示?

  

http://staging.felgenexklusiv.de/felge/asa-gt1

这是我现有的.htaccess文件:

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /
  RewriteRule ^index\.php$ - [L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . /index.php [L]
</IfModule>

2 个答案:

答案 0 :(得分:1)

DirectoryIndex index.php
<IfModule mod_rewrite.c>
 RewriteEngine On
 RewriteBase /
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule ^/([a-zA-Z]+)/([a-zA-Z0-9\-]+)?/?(.*)$ index.php?partie=$1&name=$2&%{QUERY_STRING} [L,QSA]
</IfModule>

答案 1 :(得分:1)

</IfModule>插入这些行之前:

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

RewriteRule ^(felge)/(.*)/?$ /?$1=$2 [NC,L,QSA]