2014-04-19 57 views
0

我遇到了麻煩,因爲我想我的網址SEO友好。而這一切都很好,但我不能在URL中去,而無需使用.PHPhtaccess mod_rewrite沒有.php

我的網址是:

http://rasolutions.eu/blogitem?id=3 

而且我希望它是:

http://rasolutions.eu/blogitem/3/ 

我搜索在線和我編寫的代碼,使它的工作,唯一的問題是,我不能去的URL,除非我使用.php 我的htaccess代碼是這樣的(我是一個noob,如果涉及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

您可以刪除第二和第三'RewriteEngine敘述On',因爲它被打開了。 – Howli

回答

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 

在Multiviews應該允許Apache將搜索出最匹配的,例如沒有「.php」擴展名。

祝你好運!

+0

感謝您的快速回復。它幾乎可行,唯一的問題是博客/ 1 /作品,但blogitem/1 /沒有。我不知道爲什麼。如果我要去http://rasolutions.eu/blogitem/6/,它會將我發送到http://rasolutions.eu/blogitem/6/blog – RezaM

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]