简体   繁体   中英

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]

Also use base tag

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

On cloud server the code of .htaccess file is

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]

and the base tag is

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

The VM instance link of GCP such that you can see how website behave website link

If I manually type the url http://your_IP/contact.php working. But if I use http://your_IP/contact is not working

Based on your shown samples only, could you please try following Rules once. Please make sure you clear your browser cache before testing your URLs. There were multiple issues in your htaccess file, like conditions were not there, multiviews(which we came to know later in comments was ON) which made issues in your code.

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]

EDIT by OP:

Please before you go forward please check .htaccess is enable it. If you don't know is enable or disable then type ---- in your .htaccess file, if it shows 500 internal error then its enable or it's disable. Then try to enable by searching on internet.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM