簡體   English   中英

.htaccess SEO友好URL不起作用

[英].htaccess SEO friendly URLs not working

我有個問題。 我花了最后兩個小時在論壇上進行搜索,但還沒有找到為什么我的htaccess配置無法正常運行的答案。

這是我的.htaccess:

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.myserver.com/$1 [R]
RewriteCond %{SERVER_PORT} 443
RewriteRule ^block/([a-zA-Z0-9]+)/$ block.php?id=$1 [L]
RewriteCond %{SERVER_PORT} 443
RewriteRule ^tx/([a-zA-Z0-9]+)/$ tx.php?id=$1 [L]
RewriteCond %{SERVER_PORT} 443
RewriteRule ^address/([a-zA-Z0-9]+)/$ address.php?id=$1 [L]
RewriteCond %{SERVER_PORT} 443
RewriteRule ^block/([a-zA-Z0-9]+)$ block.php?id=$1 [L]
RewriteCond %{SERVER_PORT} 443
RewriteRule ^tx/([a-zA-Z0-9]+)$ tx.php?id=$1 [L]
RewriteCond %{SERVER_PORT} 443
RewriteRule ^address/([a-zA-Z0-9]+)$ address.php?id=$1 [L]

RewriteEngine可以正常工作,我可以在啟動http:... myserver.com時確認它是否重定向到https:... myserver.com。

但是,我的SEO友好URL不能正常工作。 當啟動https://myserver.com/block/12345時,我在error.log中僅收到一條錯誤消息:

[Tue Jan 07 22:08:07 2014] [error] [client 77.186.33.111] File does not exist: /var/www/block

因此,顯然它沒有重寫任何內容。

我將不勝感激,我一定在做一些嚴重錯誤的事情,但是為了上帝,我無法弄清楚自己。

謝謝

您得到404,是因為RewriteRule期望在末尾加斜杠,但您的URI沒有一個斜杠。

以此替換您的代碼,然后重試:

Options +FollowSymLinks -MultiViews

RewriteEngine On
RewriteBase /

RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://www.myserver.com/$1 [R,L,NE]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^([^/]+)/([^/]+)/?$ $1.php?id=$2 [L,QSA]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM