mod_rewrite删除?page = fine,get& id = not working

时间:2016-07-06 11:42:09

标签: .htaccess mod-rewrite

我让我的.htaccess正常工作,它正确地来自: webshop/index.php?page=homewebshop/home

如果我将ID放在网址中,它仍然需要webshop/product&id=1。我想要创建的是webshop/product/1
我在互联网上搜索了很多选项但却无法正常工作。下面的代码是我的.htaccess文件。

Options +FollowSymLinks -MultiViews
RewriteEngine On

# Removes index.php from URL 
RewriteCond %{THE_REQUEST} /index\.php [NC]
RewriteRule ^(.*?)index\.php$ /$1 [L,R=302,NC,NE]

# Rewrites /home to be /index.php?page=home
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^webshop/([^/]*)$ /webshop/?page=$1 [QSA]

希望你们能帮助我。

1 个答案:

答案 0 :(得分:3)

您可以使用:

Options +FollowSymLinks -MultiViews
RewriteEngine On

# Removes index.php from URL 
RewriteCond %{THE_REQUEST} /index\.php [NC]
RewriteRule ^(.*?)index\.php$ /$1 [L,R=302,NC,NE]

# skip all files and directories from rewrite rules below
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]

# Rewrites /webshop/product/1 to be /webshop/index.php?page=product&id=1
RewriteRule ^webshop/([^/]+)/(\d+)/?$ /webshop/?page=$1&id=$2 [NC,QSA,L]

# Rewrites /webshop/home to be /webshop/index.php?page=home
RewriteRule ^webshop/([^/]*)$ /webshop/?page=$1 [NC,QSA,L]

如果您的ID不仅是一个数字

,您可以将(\d+)更改为([^/]+)