我需要从
更改.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]
提前致谢。 :)
答案 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/