用htaccess删除部分网址(并重定向?)

时间:2013-12-06 08:19:09

标签: .htaccess

我需要从

更改.htaccess更改网址
http://mywebsite.com/p/info/team/contact/

http://mywebsite.com/info/team/contact/

http://mywebsite.com/article.php?id=ID

http://mywebsite.com/article-ID/

我只有那段代码:

RewriteRule ^article-([0-9]+)/([a-zA-Z0-9-]+)$ /article.php?id=$1 [L]
RewriteRule ^article-(.*)/ /article.php?id=$1

我的.htaccess(包含虚拟主机内容):

RewriteEngine On

# subdomeny (s nebo bez www na zacatku)

RewriteCond %{REQUEST_URI} !^subdom/
RewriteCond %{REQUEST_URI} !^/subdom/
RewriteCond %{HTTP_HOST} ^(www\.)?(.*)\.([^\.]*)\.([^\.]*)$
RewriteCond %{DOCUMENT_ROOT}/subdom/%2 -d
RewriteRule (.*) subdom/%2/$1 [DPI]

# aliasy - spravne presmerovani pri chybejicim /

RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^domains/[^/]+/(.+[^/])$ /$1/ [R]

# subdomeny - spravne presmerovani pri chybejicim /

RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^subdom/[^/]+/(.+[^/])$ /$1/ [R]

#errory - presmerovani
ErrorDocument 404 /errors/404-not-found/

RewriteRule ^p/(.*)$ /$1 [NC,L,R]

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

提前致谢。 :)

1 个答案:

答案 0 :(得分:0)

您的DOCUMENT_ROOT/.htaccess文件中需要以下两条规则:

RewriteEngine On

RewriteRule ^p/(.*)$ /$1 [NC,L,R]
RewriteRule ^article-(.+?)/?$ /article.php?id=$1 [L,QSA,NC]

完整.htaccess:

RewriteEngine On

RewriteRule ^p/(.*)$ /$1 [NC,L,R]

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

# subdomeny (s nebo bez www na zacatku)

RewriteCond %{REQUEST_URI} !^subdom/
RewriteCond %{REQUEST_URI} !^/subdom/
RewriteCond %{HTTP_HOST} ^(www\.)?(.*)\.([^\.]*)\.([^\.]*)$
RewriteCond %{DOCUMENT_ROOT}/subdom/%2 -d
RewriteRule (.*) subdom/%2/$1 [DPI]

# aliasy - spravne presmerovani pri chybejicim /
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^domains/[^/]+/(.+[^/])$ /$1/ [L,R]

# subdomeny - spravne presmerovani pri chybejicim /
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^subdom/[^/]+/(.+[^/])$ /$1/ [L,R]

#errory - presmerovani
ErrorDocument 404 /errors/404-not-found/