我遇到了htaccess的麻烦,因为我希望我的网址SEO友好。这一切都很好,但我不能在不使用.php
的情况下使用URL我的网址是:
http://rasolutions.eu/blogitem?id=3
我希望它是:
http://rasolutions.eu/blogitem/3/
我在网上搜索过,我编写了使其正常运行的代码,唯一的问题是除非我使用.php,否则我无法访问该网址 我的htaccess代码是这个(如果涉及到htaccess,我就是一个菜鸟):
ErrorDocument 404 /404.php
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
# WWW to not WWW.
RewriteCond %{HTTP_HOST} ^www\.rasolutions\.eu$
RewriteRule ^/?$ "http\:\/\/rasolutions\.eu\/" [R=301,L]
# No PERL access/
RewriteCond %{HTTP_USER_AGENT} libwww-perl.*
RewriteRule .* – [F,L]
RewriteEngine On
RewriteRule ^blogitem/([0-9]+)/$ blogitem.php?id=$1 [NC,L]
RewriteEngine On
RewriteRule ^blog/([0-9]+)/$ blog.php?page=$1 [NC,L]
# Home redirect.
DirectoryIndex home.php
非常感谢您的帮助!对不起英语不好,这不是我的母语。
答案 0 :(得分:1)
试试这个:
ErrorDocument 404 /404.php
Options +MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
# WWW to not WWW.
RewriteCond %{HTTP_HOST} ^www\.rasolutions\.eu$
RewriteRule ^/?$ "http\:\/\/rasolutions\.eu\/" [R=301,L]
# No PERL access/
RewriteCond %{HTTP_USER_AGENT} libwww-perl.*
RewriteRule .* – [F,L]
RewriteEngine On
RewriteRule ^blogitem/([0-9]+)/$ blogitem.php?id=$1 [NC,L]
RewriteEngine On
RewriteRule ^blog/([0-9]+)/$ blog.php?page=$1 [NC,L]
# Home redirect.
DirectoryIndex home.php
多视图应该允许Apache搜索最近的匹配,例如没有“.php”扩展名。
祝你好运!
答案 1 :(得分:1)
有这样的话:
ErrorDocument 404 /404.php
# Home redirect.
DirectoryIndex home.php
Options -MultiViews
RewriteEngine On
# No PERL access/
RewriteCond %{HTTP_USER_AGENT} libwww-perl.*
RewriteRule .* – [F,L]
# WWW to not WWW.
RewriteCond %{HTTP_HOST} ^www\.rasolutions\.eu$
RewriteRule ^ http://rasolutions.eu%{REQUEST_URI} [R=301,L,NE]
RewriteRule ^blogitem/([0-9]+)/?$ blogitem.php?id=$1 [NC,L,QSA]
RewriteRule ^blog/([0-9]+)/?$ blog.php?page=$1 [NC,L,QSA]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^.]+)$ $1.php [L]