簡體   English   中英

使用 .htaccess 的 seo 友好型 url 出現錯誤

[英]Error come with seo friendly url using .htaccess

Firstly I have coded my website in localhost than everything goes fine all URL work but when I upload it on the cloud (GCP) the URL is not working(It shows that the URL is not found) the following code is of .htaccess file in localhost

RewriteEngine On
RewriteBase /blog_site/

RewriteCond %{REQUEST_FILENAME} !-d [NC]
RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteRule ^single_post/(.*)$ single_post.php?post_title=$1 
RewriteRule ^single_post/(.*)/ single_post.php?post_title=$1

RewriteRule ^category/(.*)$ category.php?category=$1 
RewriteRule ^category/(.*)/ category.php?category=$1 

RewriteRule ^author/(.*)$ author.php?author=$1 
RewriteRule ^author/(.*)/ author.php?author=$1

RewriteRule ^author/(.*)/(.*)$ author.php?author=$1&user=$2 
RewriteRule ^author/(.*)/(.*)/ author.php?author=$1&user=$2

RewriteRule ^search/(.*)$ search.php?search=$1 
RewriteRule ^search/(.*)/ search.php?search=$1 

RewriteRule ^([^\.]+)$ $1.php [NC,L]

也使用基本標簽

<base href="/blog_site/" target="_self">

在雲服務器上 .htaccess 文件的代碼是

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-d [NC]
RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteRule ^single_post/(.*)$ single_post.php?post_title=$1 
RewriteRule ^single_post/(.*)/ single_post.php?post_title=$1

RewriteRule ^category/(.*)$ category.php?category=$1 
RewriteRule ^category/(.*)/ category.php?category=$1 

RewriteRule ^author/(.*)$ author.php?author=$1 
RewriteRule ^author/(.*)/ author.php?author=$1

RewriteRule ^author/(.*)/(.*)$ author.php?author=$1&user=$2 
RewriteRule ^author/(.*)/(.*)/ author.php?author=$1&user=$2

RewriteRule ^search/(.*)$ search.php?search=$1 
RewriteRule ^search/(.*)/ search.php?search=$1 

RewriteRule ^([^\.]+)$ $1.php [NC,L]

基本標簽是

 <base href="/" target="_self">

GCP 的 VM 實例鏈接,以便您可以看到網站的行為網站鏈接

如果我手動輸入 url http://your_IP/contact.php 工作。 但是如果我使用 http://your_IP/contact 不起作用

僅根據您顯示的示例,您能否嘗試遵循規則一次。 請確保在測試 URL 之前清除瀏覽器緩存。 您的 htaccess 文件中存在多個問題,例如條件不存在,多視圖(我們稍后在評論中知道為 ON)在您的代碼中產生了問題。

Options +FollowSymLinks -MultiViews

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^single_post/(.*)/?$ single_post.php?post_title=$1 [NC,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^author/([^/]*)/(.*)/?$ author.php?author=$1&user=$2 [NC,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(category|author|search)/(.*)/?$ $1.php?$1=$2 [NC,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)/?$ $1.php [L]

由 OP 編輯:

請在 go 轉發之前檢查 .htaccess 是否啟用它。 如果您不知道是啟用還是禁用,則在 .htaccess 文件中鍵入---- ,如果顯示 500 內部錯誤,則啟用或禁用。 然后嘗試通過在互聯網上搜索啟用。

暫無
暫無

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

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