Jump to content

.htaccess problem


Recommended Posts

Hi guys,

 

Have moved my site from local server to host godaddy.

 

Had enormous trouble with on going internal server error 500, not fixed by any of the solutions already available on the forum or other websites. However, I did manage to solve it in the end.

 

When SEO settings are adjusted the regenerated file has two lines almost at the top:

 

SetEnv HTTP_MOD_REWRITE On
RewriteEngine on
 
At this stage I'm assuming that because its a shared server there is a file at a higher level with these instructions in it and so it doesn't like being told twice. I can manually remove the lines and then everything works fine. However, this means that whenever I change any SEO & URL settings in the back office my site goes down, and I have to then manually download the htaccess file via ftp, change it and reupload it, which is a pain in the arse.
 
But (and here's the actual question) surely there's a presatshop file that is responsible for generating the htaccess file, and I could alter it so that those to lines are not added with every regeneration..  but where is the file..?  I can't for the life of me find something that performs that function..
Link to comment
Share on other sites

Is the code above this line ...

 

# ~~start~~ Do not remove this comment, Prestashop will keep automatically the code outside this comment when .htaccess will be generated again

 

No, the code is within the section automatically generated by prestashop, I have to remove it everytime, and with each new generation it puts it back.

 

If I was somehow able to override it by placing something above then that would be an acceptable solution - but knowing what to write to achieve that is beyond my knowledge.

Link to comment
Share on other sites

In BO > Preferences  > SEO & URLs have you tried Disable apache multiviews?

 

Yes, spent ages with that when I first moved to the godaddy host. I tried to use that setting via the BO, and I tried inputing it manually, either way I still get a 500 error.

 

After reviewing the servers error log, and seeing this:

"public_html/mystore/.htaccess: Invalid command 'SetEnv', perhaps misspelled or defined by a module not included in the server configuration"

 

I removed the line:

"SetEnv HTTP_MOD_REWRITE On"
 
and subsequently:
"RewriteEngine on"
 
..and then the site works with friendly URLs active.
 
I have the solution to the 500 error - I only need to know how to alter the way prestashop generates the htaccess file - not via the BO, via changing the actual code. There is no BO option to do what I want to do.
Edited by ajspiano (see edit history)
  • Like 1
Link to comment
Share on other sites

I have a site currently set with friendly URLS on and I don't touch the PS generated code. I just put this above the write line. Change the 2 lines with yourdomain.com.

 

Shouldn't hurt to try.

 

RewriteEngine On
RewriteCond %{HTTP_HOST} !^YourDomain.com$
RewriteRule (.*) http://yourdomain.com/$1 [R=301,L]

# ~~start~~ Do not remove this comment, Prestashop will keep automatically the code outside this comment when .htaccess will be generated again

Link to comment
Share on other sites

Hi,

 

.htaccess is required for friendly URLs and it is generated every time you make a change in SEO & URLs. The file is going to be generated no matter what. 

 

If you disable Friendly URLs the file will not be generated.

 

Now to your problem : SetEnv is available with apache module mod_env. You can read about it http://httpd.apache.org/docs/2.2/mod/mod_env.html Ask your host to enable that apache module. 

 

If you change the code like this :

 

<IfModule mod_env.c>
SetEnv HTTP_MOD_REWRITE On
</IfModule>

The above code means that SetEnv is used only when mod_env is available. This will not cause any 500 error. But since it is generated by prestahop, you can consider adding this line in the file where El Patron has mentioned. If you tell me the prestashop version you are using. I will probably suggest you where to change.

Edited by ibndawood (see edit history)
  • Like 1
Link to comment
Share on other sites

Hi guys, 

 

Thanks for your help.

 

Elpatron - Thanks, exactly what I needed to know.

 

ibndawood - an if command seems like a good idea, i think the mod_env thing went a little over my head though and so I didn't try that yet, I will have to read up on the apache link you posted.

 

I did however modify tools.php function generatehtaccess in the following way. The question remains though, is this a good idea generally? (as opposed to utilising an 'if' construct) and will I remember what to undo it if I move to a different server later down the track? (probably not :/)

		// RewriteEngine
		fwrite($write_fd, "<IfModule mod_rewrite.c>\n");

		// Ensure HTTP_MOD_REWRITE variable is set in environment
		/* COMMENTED TO REMOVE FROM htaccess file 
		 * fwrite($write_fd, "SetEnv HTTP_MOD_REWRITE On\n");*/

		// Disable multiviews ?
		if ($disable_multiviews)
			fwrite($write_fd, "\n# Disable Multiviews\nOptions -Multiviews\n\n");

		/* COMMENTED TO REMOVE FROM htaccess file 
		 * fwrite($write_fd, "RewriteEngine on\n"); */
	
		if (!$medias)
			$medias = array(_MEDIA_SERVER_1_, _MEDIA_SERVER_2_, _MEDIA_SERVER_3_);

I have now also allowed prestashop to regenerate my htaccess file and there has been no 500 error resulting from it.

 

 

Link to comment
Share on other sites

Prestashop 1.5.6.1 actually uses this IfModule tag. This is from prestashop 1.5.6.1 classes/Tools

// Ensure HTTP_MOD_REWRITE variable is set in environment
		fwrite($write_fd, "<IfModule mod_env.c>\n");
		fwrite($write_fd, "SetEnv HTTP_MOD_REWRITE On\n");
		fwrite($write_fd, "</IfModule>\n\n");

It is a good idea if you use override instead of directly modifying the core. Create a file Tools.php in override/classes and the class should be like Tools extends ToolsCore. In that what you don't have any problems while upgrading. 

Link to comment
Share on other sites

 

I did however modify tools.php function generatehtaccess in the following way. The question remains though, is this a good idea generally? (as opposed to utilising an 'if' construct) and will I remember what to undo it if I move to a different server later down the track? (probably not :/)

		// RewriteEngine
		fwrite($write_fd, "<IfModule mod_rewrite.c>\n");

		// Ensure HTTP_MOD_REWRITE variable is set in environment
		/* COMMENTED TO REMOVE FROM htaccess file 
		 * fwrite($write_fd, "SetEnv HTTP_MOD_REWRITE On\n");*/

		// Disable multiviews ?
		if ($disable_multiviews)
			fwrite($write_fd, "\n# Disable Multiviews\nOptions -Multiviews\n\n");

		/* COMMENTED TO REMOVE FROM htaccess file 
		 * fwrite($write_fd, "RewriteEngine on\n"); */
	
		if (!$medias)
			$medias = array(_MEDIA_SERVER_1_, _MEDIA_SERVER_2_, _MEDIA_SERVER_3_);

I have now also allowed prestashop to regenerate my htaccess file and there has been no 500 error resulting from it.

 

Some hoster disable the apache module SetEnv for security reasons. The code in the latest prestashop version looks different to the one you have posted. It looks like this

 

 

// Ensure HTTP_MOD_REWRITE variable is set in environment
		fwrite($write_fd, "<IfModule mod_env.c>\n");
		fwrite($write_fd, "SetEnv HTTP_MOD_REWRITE On\n");
		fwrite($write_fd, "</IfModule>\n\n");

So, you shouldn't need to comment due to the if condition ... which prestashop version are you using?

 

sniped by ibndawood :)

Edited by prestamax (see edit history)
Link to comment
Share on other sites

I'm using 1.5.6.0

 

So i can place this code..

// Ensure HTTP_MOD_REWRITE variable is set in environment
        fwrite($write_fd, "<IfModule mod_env.c>\n");
        fwrite($write_fd, "SetEnv HTTP_MOD_REWRITE On\n");
        fwrite($write_fd, "</IfModule>\n\n");

 

Great, can I also put the other problem line in there, or perhaps does it make sense to? or should I have a separate if test for "RewriteEngine on"

Link to comment
Share on other sites

This is how the code looks like in 1.5.6.1

// RewriteEngine
		fwrite($write_fd, "<IfModule mod_rewrite.c>\n");

		// Ensure HTTP_MOD_REWRITE variable is set in environment
		fwrite($write_fd, "<IfModule mod_env.c>\n");
		fwrite($write_fd, "SetEnv HTTP_MOD_REWRITE On\n");
		fwrite($write_fd, "</IfModule>\n\n");

		// Disable multiviews ?
		if ($disable_multiviews)
			fwrite($write_fd, "\n# Disable Multiviews\nOptions -Multiviews\n\n");

		fwrite($write_fd, "RewriteEngine on\n");

and the .htaccess file

# ~~start~~ Do not remove this comment, Prestashop will keep automatically the code outside this comment when .htaccess will be generated again
# .htaccess automaticaly generated by PrestaShop e-commerce open-source solution
# http://www.prestashop.com - http://www.prestashop.com/forums

<IfModule mod_rewrite.c>
<IfModule mod_env.c>
SetEnv HTTP_MOD_REWRITE On
</IfModule>

RewriteEngine on
RewriteCond %{HTTP_HOST} ^localhost$
RewriteRule . - [E=REWRITEBASE:/~ibrahim/prestashopv1.5.6.1/]
RewriteRule ^api/?(.*)$ %{ENV:REWRITEBASE}webservice/dispatcher.php?url=$1 [QSA,L]

# Images
RewriteCond %{HTTP_HOST} ^localhost$
RewriteRule ^([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$1$2$3.jpg [L]
RewriteCond %{HTTP_HOST} ^localhost$
RewriteRule ^([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$1$2$3$4.jpg [L]
RewriteCond %{HTTP_HOST} ^localhost$
RewriteRule ^([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$1$2$3$4$5.jpg [L]
RewriteCond %{HTTP_HOST} ^localhost$
RewriteRule ^([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$1$2$3$4$5$6.jpg [L]
RewriteCond %{HTTP_HOST} ^localhost$
RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$5/$1$2$3$4$5$6$7.jpg [L]
RewriteCond %{HTTP_HOST} ^localhost$
RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$5/$6/$1$2$3$4$5$6$7$8.jpg [L]
RewriteCond %{HTTP_HOST} ^localhost$
RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$5/$6/$7/$1$2$3$4$5$6$7$8$9.jpg [L]
RewriteCond %{HTTP_HOST} ^localhost$
RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$5/$6/$7/$8/$1$2$3$4$5$6$7$8$9$10.jpg [L]
RewriteCond %{HTTP_HOST} ^localhost$
RewriteRule ^c/([0-9]+)(\-[\.*_a-zA-Z0-9-]*)(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/c/$1$2$3.jpg [L]
RewriteCond %{HTTP_HOST} ^localhost$
RewriteRule ^c/([a-zA-Z_-]+)(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/c/$1$2.jpg [L]
# AlphaImageLoader for IE and fancybox
RewriteCond %{HTTP_HOST} ^localhost$
RewriteRule ^images_ie/?([^/]+)\.(jpe?g|png|gif)$ js/jquery/plugins/fancybox/images/$1.$2 [L]

# Dispatcher
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{HTTP_HOST} ^localhost$
RewriteRule ^.*$ - [NC,L]
RewriteCond %{HTTP_HOST} ^localhost$
RewriteRule ^.*$ %{ENV:REWRITEBASE}index.php [NC,L]
</IfModule>

<IfModule mod_expires.c>
	ExpiresActive On
	ExpiresByType image/gif "access plus 1 month"
	ExpiresByType image/jpeg "access plus 1 month"
	ExpiresByType image/png "access plus 1 month"
	ExpiresByType text/css "access plus 1 week"
	ExpiresByType text/javascript "access plus 1 week"
	ExpiresByType application/javascript "access plus 1 week"
	ExpiresByType application/x-javascript "access plus 1 week"
	ExpiresByType image/x-icon "access plus 1 year"
</IfModule>

FileETag INode MTime Size
<IfModule mod_deflate.c>
	<IfModule mod_filter.c>
		AddOutputFilterByType DEFLATE text/html text/css text/javascript application/javascript application/x-javascript
	</IfModule>
</IfModule>

#If rewrite mod isn't enabled
ErrorDocument 404 /~ibrahim/prestashopv1.5.6.1/index.php?controller=404

# ~~end~~ Do not remove this comment, Prestashop will keep automatically the code outside this comment when .htaccess will be generated again

Make sure your open and close tags are matching.

Link to comment
Share on other sites

back up before doing so.

 

I think what would really help is knowing what the 500 error really is.  Can you  turn on errors and tell us the underlying error  message?

 

I've been avoiding updating prestashop, mostly because I initially (stupidly) made quite a few modifications to files that will perhaps be overwritten..  and the version I have functions fine, I don't want to create problems for myself and delay getting the shop live even further.

 

While I was trying to figure out the error I turned on error reporting within prestashop but its didn't really tell me anything, i gather because the 500 error was happening so early, before any prestashop code was being processed (maybe? i dont really know) ..maybe I don't know where to look?

 

I did post my servers error message up above, but here it is again:

public_html/mystore/.htaccess: Invalid command 'SetEnv', perhaps misspelled or defined by a module not included in the server configuration 

Edited by ajspiano (see edit history)
Link to comment
Share on other sites

 

I did post my servers error message up above, but here it is again:

public_html/mystore/.htaccess: Invalid command 'SetEnv', perhaps misspelled or defined by a module not included in the server configuration 

This is the problem. You appear to be missing mod_env in Apache. Check your Apache config to see if you can find:

LoadModule env_module /path/to/apache/library/mod_env.so

 

If not, add it and restart Apache.

 

You could check this another way by using the Apache binary:

/path/to/httpd -M

 

This will output the loaded modules.

 

If you do not know how to do this then you should contact your hosting company

Link to comment
Share on other sites

I don't have access to the apache config files because its a shared server..  strongly doubt that the host will change it just for me.

 

What are the implications of not having it? The site seems to function just fine the way it is now (not using that module) with the alterations made to tools.php and in turn the htaccess file.

Link to comment
Share on other sites

I don't have access to the apache config files because its a shared server..  strongly doubt that the host will change it just for me.

 

What are the implications of not having it? The site seems to function just fine the way it is now (not using that module) with the alterations made to tools.php and in turn the htaccess file.

 

then I'd not worry about it...mark this thing as solved and go sellf some stuff...:)

Link to comment
Share on other sites

×
×
  • Create New...