重写网址,删除类别字

时间:2013-11-28 10:34:39

标签: php .htaccess mod-rewrite url-rewriting

这是我的htaccess:

Options +FollowSymLinks RewriteEngine on

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

RewriteCond %{HTTP_HOST} ^178\.157\.87\.220 
RewriteRule ^(.*) http://www.picxeto.com/$1 [L,R=301]

RewriteRule wallpapers/(.*)/ wallpapers.php?id=$1 
RewriteRule wallpapers/(.*) wallpapers.php?id=$1

RewriteRule page/(.*)/ index.php?page=$1
RewriteRule page/(.*) index.php?page=$1

RewriteRule category/(.*)/ index.php?cat=$1 
RewriteRule category/(.*) index.php?cat=$1

RewriteRule /(.*)/page/(.*)/ index.php?cat=$1&page=$2 
RewriteRule /(.*)/page/(.*) index.php?cat=$1&page=$2

RewriteRule ^dmca$ dmca.php [NC,L]

我的问题是我必须修改所以我可以拥有这样的网址:

picxeto.com/photography不是picxeto.com/category/photography

picxeto.com/photography/2不是picxeto.com/category/photography/page/2

帮助

2 个答案:

答案 0 :(得分:0)

让你的.htaccess像这样:

Options +FollowSymLinks
RewriteEngine on

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

RewriteCond %{HTTP_HOST} ^178\.157\.87\.220
RewriteRule ^(.*)$ http://www.picxeto.com/$1 [L,R=301]

RewriteRule ^wallpapers/([^/]+)/?$ wallpapers.php?id=$1 [L,QSA]

RewriteRule ^page/([^/]+)/?$ index.php?page=$1 [L,QSA]

RewriteRule ^([^/]+)/page/([^/]+)/?$ index.php?cat=$1&page=$2 [L,QSA]

RewriteRule ^category/(.+?)/?$ $1 [R=302,NC,L]

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

RewriteRule ^dmca/?$ dmca.php [NC,L]

答案 1 :(得分:0)

您可以在htaccess中使用

RewriteRule ^category/(.+)$ http://www.picxeto.com/$1 [R=301,L]

但是如果您使用WP,则可以使用此插件 - > WP No Category Base