Post by scracingshop » Fri Apr 30, 2021 6:55 am

Hi all, i'm on Version 3.0.3.7
I am trying to remove index.php from my home page to improve the seo of my site

Every time I change .htaccess.txt to .htaccess the site shows ERROR 500 on each of its pages

Now .htaccess is disabled and the site just works like this:
https://www.scracingshop.com/index.php

Could you help me configure it correctly?
Thank you!

This is the basic htaccess code that i'm using, I didn't touch nothing just remove .txt after installed opencart:

Code: Select all

# 1.To use URL Alias you need to be running apache with mod_rewrite enabled.

# 2. In your opencart directory rename htaccess.txt to .htaccess.

# For any support issues please visit: http://www.opencart.com

Options +FollowSymlinks

# Prevent Directory listing
Options -Indexes

# Prevent Direct Access to files
<FilesMatch "(?i)((\.tpl|\.twig|\.ini|\.log|(?<!robots)\.txt))">
 Require all denied
## For apache 2.2 and older, replace "Require all denied" with these two lines :
# Order deny,allow
# Deny from all
</FilesMatch>

# SEO URL Settings
RewriteEngine On
# If your opencart installation does not run on the main web folder make sure you folder it does run in ie. / becomes /shop/

RewriteBase /
RewriteRule ^sitemap.xml$ index.php?route=extension/feed/google_sitemap [L]
RewriteRule ^googlebase.xml$ index.php?route=extension/feed/google_base [L]
RewriteRule ^system/storage/(.*) index.php?route=error/not_found [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css)
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]

### Additional Settings that may need to be enabled for some servers
### Uncomment the commands by removing the # sign in front of it.
### If you get an "Internal Server Error 500" after enabling any of the following settings, restore the # as this means your host doesn't allow that.

# 1. If your cart only allows you to add one item at a time, it is possible register_globals is on. This may work to disable it:
# php_flag register_globals off

# 2. If your cart has magic quotes enabled, This may work to disable it:
# php_flag magic_quotes_gpc Off

# 3. Set max upload file size. Most hosts will limit this and not allow it to be overridden but you can try
# php_value upload_max_filesize 999M

# 4. set max post size. uncomment this line if you have a lot of product options or are getting errors where forms are not saving all fields
# php_value post_max_size 999M

# 5. set max time script can take. uncomment this line if you have a lot of product options or are getting errors where forms are not saving all fields
# php_value max_execution_time 200

# 6. set max time for input to be recieved. Uncomment this line if you have a lot of product options or are getting errors where forms are not saving all fields
# php_value max_input_time 200

# 7. disable open_basedir limitations
# php_admin_value open_basedir none
Last edited by scracingshop on Tue Dec 28, 2021 5:32 pm, edited 1 time in total.

Newbie

Posts

Joined
Wed Jan 04, 2017 5:30 pm

Post by by mona » Fri Apr 30, 2021 11:34 am

You do not remove index.php from your urls via htaccess, you remove it from the urls you write in your html.
Although I do not recommend you make hard code changes - and make sure you have a back up always.

You do this in the file:
catalog/controller/startup/seo_url.php

find function:

Code: Select all

public function rewrite($link)
replace this:

Code: Select all

} elseif ($key == 'path') {
					$categories = explode('_', $value);

					foreach ($categories as $category) {
						$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "seo_url WHERE `query` = 'category_id=" . (int)$category . "' AND store_id = '" . (int)$this->config->get('config_store_id') . "' AND language_id = '" . (int)$this->config->get('config_language_id') . "'");

						if ($query->num_rows && $query->row['keyword']) {
							$url .= '/' . $query->row['keyword'];
						} else {
							$url = '';

							break;
						}
					}

					unset($data[$key]);
				}
				

with this:

Code: Select all

} elseif ($key == 'path') {
					$categories = explode('_', $value);
					
					foreach ($categories as $category) {
						$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "seo_url WHERE `query` = 'category_id=" . (int)$category . "' AND store_id = '" . (int)$this->config->get('config_store_id') . "' AND language_id = '" . (int)$this->config->get('config_language_id') . "'");
						
						if ($query->num_rows && $query->row['keyword']) {
							$url .= '/' . $query->row['keyword'];
						} else {
							$url = '';
							
							break;
						}
					}
					
					unset($data[$key]);
				} elseif (!in_array($data['route'],array('common/language/language','common/currency/currency','product/product','product/category','product/manufacturer/info','information/information'))) {
					// all other cases for just route settings & eliminating unnecessary queries
					if ($key == 'route') {
						// no need to query root
						if ($value == 'common/home') {
							$url = '/';
						} else {
							$sql = "SELECT * FROM " . DB_PREFIX . "seo_url WHERE `query` = '" . $this->db->escape($value) . "' AND store_id = '" . (int)$this->config->get('config_store_id') . "' AND language_id = '" . $this->config->get('config_language_id') . "'";
							$query = $this->db->query($sql);
							if ($query->num_rows) {
								if ($url != '/') $url .= '/';
								$url .= $query->row['keyword'];
								unset($data[$key]);
							}
						}
					}
				}
This will also enable you to add seo urls for any other route not just the predefined ones.

DISCLAIMER:
You should not modify core files .. if you would like to donate a cup of coffee I will write it in a modification for you.


https://www.youtube.com/watch?v=zXIxDoCRc84


User avatar
Expert Member

Posts

Joined
Mon Jun 10, 2019 9:31 am

Post by scracingshop » Fri Apr 30, 2021 4:11 pm

Thanks for your help!

I have done this, but still my homepage is with index.php to find and now when I open a product appear ERROR 404 page

You know why?

Thanks a lot again!

Newbie

Posts

Joined
Wed Jan 04, 2017 5:30 pm

Post by by mona » Fri Apr 30, 2021 5:55 pm

Have you set Use SEO URLs in system/settings server tab?
& check you have no spaces or odd characters in your so keywords

https://www.youtube.com/watch?v=5Y7DFjAKf-I

DISCLAIMER:
You should not modify core files .. if you would like to donate a cup of coffee I will write it in a modification for you.


https://www.youtube.com/watch?v=zXIxDoCRc84


User avatar
Expert Member

Posts

Joined
Mon Jun 10, 2019 9:31 am

Post by ADD Creative » Fri Apr 30, 2021 6:20 pm

scracingshop wrote:
Fri Apr 30, 2021 6:55 am
Every time I change .htaccess.txt to .htaccess the site shows ERROR 500 on each of its pages

This is the basic htaccess code that i'm using, I didn't touch nothing just remove .txt after installed opencart:
Try commenting out or removing the following line.

Code: Select all

Options +FollowSymlinks

www.add-creative.co.uk


Expert Member

Posts

Joined
Sat Jan 14, 2012 1:02 am
Location - United Kingdom

Post by scracingshop » Fri Apr 30, 2021 6:28 pm

ADD Creative wrote:
Fri Apr 30, 2021 6:20 pm
scracingshop wrote:
Fri Apr 30, 2021 6:55 am
Every time I change .htaccess.txt to .htaccess the site shows ERROR 500 on each of its pages

This is the basic htaccess code that i'm using, I didn't touch nothing just remove .txt after installed opencart:
Try commenting out or removing the following line.

Code: Select all

Options +FollowSymlinks
It worked!!! THANKS! Now SEO seems to work pretty good :)

But there is a little problem more.. When I search for http://www.scracingshop.com it give me error plesk.. it work only as it http://www.scracingshop.com/index.php

How can fix also this? Thanks :))!

Newbie

Posts

Joined
Wed Jan 04, 2017 5:30 pm

Post by ADD Creative » Fri Apr 30, 2021 6:37 pm

I think you will need to contact your host about that issue.

www.add-creative.co.uk


Expert Member

Posts

Joined
Sat Jan 14, 2012 1:02 am
Location - United Kingdom

Post by scracingshop » Fri Apr 30, 2021 6:49 pm

Fixed all, there was two index in my root.

- index.php
-index.html

Now it work

Thanks a lot for your support guys , case closed :)

Newbie

Posts

Joined
Wed Jan 04, 2017 5:30 pm

Post by straightlight » Fri Apr 30, 2021 7:16 pm

Now that the issue has been solved, please add: [SOLVED] at the beginning of the subject line on your first post.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by BillionDollars » Wed Oct 06, 2021 11:54 pm

Hi, Guys and girls.

Some useful information to add to this topic, hope it will help others too.

For anyone that also struggles again with this error 500 after changing the .htaccess.txt to .htaccess. Your servers provider runs on Apache probably and the server is for security reasons set that it is not allowed.

In the .htaccess.txt document find this:
Options +FollowSymLinks

and replace it with:

Options +SymLinksIfOwnerMatch

Then save it and rename the .htaccess.txt to .htaccess and you will be okay. I just did it today October 6, 2021, and it works.

Blessings


Posts

Joined
Mon Jan 27, 2020 2:40 am
Who is online

Users browsing this forum: Amazon [Bot], JNeuhoff and 134 guests