SEO 友好的 URL 正在工作,但主页不再工作
SEO friendly URLs IS working but homepage doesn't work anymore
我想在我的网站上使用 SEO 友好的 URL,所以我将以下代码写入我的 .htaccess 文件:
# url rewrite query string removal....
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ index.php?pagina=
# url rewrite query string removal....
或下面的代码(不同时使用,两者对我来说似乎都一样)
# url rewrite query string removal..
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/\.]+)/?$ index.php?pagina=
# TEST
# url rewrite query string removal..
两者都适用于除 1 页以外的所有页面。如果我尝试访问域,我的主页将无法正常工作,例如 www.example.com 无法正常工作,但 www.example.com/home 可以正常工作。
我的问题是:我怎样才能拥有 SEO 友好的主页,如果:
原来的url是http://www.example.com/index.php?pagina=home AND if I use the .htaccess code it will be http://www.example.com/home但是我不喜欢www.example.com/home作为我的主页,我想把主页改写成www.example.com 和所有其他的应该在 www.example.com/filename 中,文件名可以是任何可以在 /pagina/ 文件夹中找到的文件名。
如何将主页设置为 www.example.com 而不是 www.example.com/home 而不会出现任何错误,哪种 .htaccess 代码最适合我?
您可以对 /home
进行重定向,并在当前规则之前保留该规则。
这样说:
DirectoryIndex index.php
RewriteEngine On
RewriteRule ^home/?$ / [L,R=302,NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ index.php?pagina= [L,QSA]
# url rewrite query string removal....
我想在我的网站上使用 SEO 友好的 URL,所以我将以下代码写入我的 .htaccess 文件:
# url rewrite query string removal....
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ index.php?pagina=
# url rewrite query string removal....
或下面的代码(不同时使用,两者对我来说似乎都一样)
# url rewrite query string removal..
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/\.]+)/?$ index.php?pagina=
# TEST
# url rewrite query string removal..
两者都适用于除 1 页以外的所有页面。如果我尝试访问域,我的主页将无法正常工作,例如 www.example.com 无法正常工作,但 www.example.com/home 可以正常工作。
我的问题是:我怎样才能拥有 SEO 友好的主页,如果:
原来的url是http://www.example.com/index.php?pagina=home AND if I use the .htaccess code it will be http://www.example.com/home但是我不喜欢www.example.com/home作为我的主页,我想把主页改写成www.example.com 和所有其他的应该在 www.example.com/filename 中,文件名可以是任何可以在 /pagina/ 文件夹中找到的文件名。
如何将主页设置为 www.example.com 而不是 www.example.com/home 而不会出现任何错误,哪种 .htaccess 代码最适合我?
您可以对 /home
进行重定向,并在当前规则之前保留该规则。
这样说:
DirectoryIndex index.php
RewriteEngine On
RewriteRule ^home/?$ / [L,R=302,NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ index.php?pagina= [L,QSA]
# url rewrite query string removal....