我有一个网站,比如说' www.example.com'
,我也在这个网站上创建了子域,比如'www.alpha.example.com'
。我需要将一个动态页面转换为SEO友好的URL。我的URL是'www.alpha.example.com/test/article.php?cat=people'
进入
'www.alpha.example.com/test/article/people'
如何使用.htacces
解决此问题
请帮帮我。
为了完整性,我会这样做。这样,如果他们输入www.alpha.example.com/test/article.php?cat=people
,则它将重定向到www.alpha.example.com/test/article/people
,因此您将获得双向保险。
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www.)?alpha.example.com$ [NC]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9} /test/article.php?cat=([^& ]+)
RewriteRule .* /test/article/%1? [R=301,L]
RewriteCond %{HTTP_HOST} ^(www.)?alpha.example.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^test/article/([^/]+)/?$ /test/article.php?cat=$1 [NC,L]
在www.alpha.example.com
的DocumentRoot
内部创建一个名为.htaccess
的文件,代码为:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www.)?alpha.example.com$ [NC]
RewriteRule ^test/article/([^/]+)/?$ test/article.php?cat=$1 [L,NC,QSA]