Reviews in Magento don't work after changing .htaccess - .htaccess

I need help. My store is running on Magento CE 1.9 and I wanted either add trailing slash to all my urls in Magento, or to get rid of it. Adding trailing slash didn't work, because some images and other linked files didn't want to load, so I added this in my .htaccess file, to get rid of trailing slash:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_HOST} !^\.localhost$ [NC]
RewriteRule ^(.+[^/])/$ http://%{HTTP_HOST}/$1 [R=301,L,NE]
The slash disappeared, and the website was rendering correctly. However, now I noticed that reviews of my products don't get registered at all. The customer can click on the link to write a review, however, after clicking submit button the page refreshes, but there is no message that the reviews is successfully submitted. The reviews also doesn't get registered in the admin panel.
Maybe some other modules don't work as well, but I still didn't notice.
This is how the link looks without the code above:
http://xxxxxxx.com/review/product/list/id/1/category/3#review-form
And this is how the link looks with the code above:
http://xxxxxxx.com/review/product/list/id/1/category/3#review-form

Hope this work,
try this rule instead
RewriteCond %{REQUEST_URI} !\.(php|phtml|html?|ico|pdf|flv|jpg|jpeg|png|gif|svg|js|css|swf|otf|woff|ttf|eot|xml|GIF|sql)$
RewriteRule ^(.*)([^/])$ http://%{HTTP_HOST}/$1$2/ [L,R=301]
This will add trailing slash to all url if the condition is meet.
Note :
this will redirect the ajax url in onepage checkout also, so if you are using SSL in onepage checkout, add slash manually to all request url, or else this will cause error

go to your frontend//default/template/review/form.phtml file and add
<?php echo $this->getBlockHtml('formkey'); ?> just after the <form> tag if it is not present there

Related

Redirect all pages to the index page

I have a temporary static HTML page. But there are a bunch of URL's added to an other website. All these URL's go to page a that doesn't exist at the moment. So it needs to be redirected to the index page.
So every page needs to be redirected to https://experienceantwerp.be
Example page that doesn't exist at the moment: https://experienceantwerp.be/nl/aanbod/gidsenwandelingen/geschiedenis/voetgangerstunnel
When you go to that URL, the styles are gone.
My current .htaccess file is
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.html/$1 [L]
When I try this, for example: https://experienceantwerp.be/hfhfhf it seems to work. I guess if there is one slash in the URL, it works.
Update: I've found a solution, but it doesn't feel right. When I add the CSS and JS file with there absolute path, it works.

How to remove the parent from current url path while redirecting using .htaccess

I have been struggling with .htaccess modifications over my site throughout. Here is what i need
I am redirecting user to login page with following url rewritting rule in
.htaccess:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^welcome/ index.php [L]
RewriteRule ^log-in/$ log-in.php [L]
The login page when called, the url path that appears in the browser looks like this
http://localhost:90/vrp/log-in/
On login page i have a link added for forget password
<a class="color-aqua" href="forget-password/">click here</a> to reset your password.</p>
Rule for rewritting it is
#Forget Password Rule#
RewriteRule ^forget-password/$ forget-password.php [NC,L]
The Forget password page when called, the url path that appears in the browser looks like this
http://localhost:90/vrp/log-in/forget-password/
I do not want that /log-in to be their on url path. It should be
http://localhost:90/vrp/forget-password/
I did a lot more search and edit stuff around but at the end could not find any way to do it. Is the required thing is possible because this is kind of appending format which may further maximize the url path when user moves in to the portal which may confuse in future.

Mod_Rewrite for URL with multiple variables | .htaccess

I develop an e-shop site with products so for this proposal i made a product page for each of products with Mod_Rewrite for URL with the code above in my .htaccess file
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*/([a-zA-Z0-9_-]+)|([a-zA-Z0-9_-]+))$ ./product.php?name=$1 [L]
So when user clicks on the link www.example.com/Nike-Air goes to Nike-Air shoes page and etc.
What i would like to do is to add one parameter more in the url, let's say size
RewriteRule ^(.*/([a-zA-Z0-9_-]+)|([a-zA-Z0-9_-]+))$ ./product.php?name=$1&size=$2 [L]
but this parameter to not append in the url, still to displays www.example.com/Nike-Air
and also to be able to get the size data from $_GET method.
Is it possible?
Any ideas guys?

htacces - need to fix broken links coming from other sites to mine

I am having an issue where Google Webmaster Tools is reporting a ton of 404 links to my site which are coming from ask.com.
I have tried to get ask.com to fix their side but of course they are not, so now I am stuck with over 11k of bad links to my site which I am suspecting is effecting my ranks right now.
Anyways I have a possible way to 301 them, but not sure how to do it with .htaccess.
Here is the bad link pointing to my site
http://www.freescrabbledictionary.com/sentence-examples/fere-film/feverous/about.php
It should be
http://www.freescrabbledictionary.com/sentence-examples/fere-film/feverous/
Besides the about.php there are other variations of endings as well, I basically need to be able to remove the ending.
Problem is that the URL after /sentence-examples/ can change. The beginning is always:
http://www.freescrabbledictionary.com/sentence-examples/
So basically:
http://www.freescrabbledictionary.com/sentence-examples/<-keep but can change->/<-keep but can change->/<-remove this->
This .htaccess should be placed on the folder before sentence-examples:
RewriteEngine on
# Redirect /sentence-examples/anything/anything/remove to /sentence-examples/anything/anything/
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(sentence-examples/[^/]+/[^/]+)/.* [NC]
RewriteRule ^ /%1/? [R=302,PT,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/(.*)$ /sentence-examples/examplesentence.php?havethis=$1&word=$2 [L]
Change 302 to 301 once you confirm it's working as expected.
If you have a CMS installed you might need a different rule to work along with it without conflicting.
Keep in mind that if you had previously tried different redirects using 301 aka permanent redirect its recommended that you use a different browser to test this rule to avoid the caching.
This is possibly quick and dirty but I've done a simple test on localhost and here just to make sure it works.
RewriteEngine On
RewriteRule ^sentence-examples/(.*)/(.*)/(.*)\.php http://www.freescrabbledictionary.com/sentence-examples/$1/$2/ [R=301,L]
You can see that I've added wildcard groups (.*) to the RewriteRule so that we can pick up the elements of the URL that we need to aid in proper redirection i.e. $1 and $2. You can also use the third one ($3) to get which destinations are being targeted alot for your SEO needs.
NB: The rule above assumes that that the redirected URL will always be from a .php target and to ensure that you can redirect regardless of whatever comes after the 3rd URL segment replace the RewriteRule with this
RewriteRule ^sentence-examples/(.*)/(.*)/(.*)$ http://www.freescrabbledictionary.com/sentence-examples/$1/$2/ [R=301,L]

.htaccess, proper rewriting of directory and file with same name

As of now my website has a few static pages, one of which is /portfolio. Among other things, my htaccess hides the .html extension. I'd like to add a portfolio directory, but I do not want to move my existing portfolio page into the portfolio directory as the default index file. My /portfolio page is one of my Google sitelinks and I am afraid if it is moved or if the url changes in someway, Google will consider it to be a brand new page.
My problem is once I add the /portfolio/ directory, whenever I try to visit the original /portfolio page, a trailing slash is automatically added and it links to the directory itself.
I've tried countless options, one being a rewrite of /portfolio/ to /portfolio, however this creates an infinite loop. I also tried "DirectorySlash Off" but that only removed the trailing slash while being inside the directory, it didn't revert access to the original /portfolio page.
Ultimately, I would like to keep my /portfolio page as-is, linking to pages inside the directory like so /portfolio/example and if either /portfolio or /portfolio/ is accessed it will result in showing the same page which is outside of the directory without Google thinking it is duplicate content.
A similar question exists here:
.htaccess rewriting url to page or directory though this still resulted in an infinite loop for me for some reason, I'm guess it has something to do with the hidden extensions.
Here's my htaccess-
RewriteEngine On
# HTML to PHP
RemoveHandler .html .htm
AddType application/x-httpd-php .htm .html
# Hide extension
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html
# Force WWW
RewriteCond %{HTTP_HOST} ^mydomain\.net
RewriteRule ^(.*)$ http://www.mydomain.net/$1 [R=301,L]
# Blog Subdomain
RewriteCond %{HTTP_HOST} ^blog.mydomain.net$
RewriteRule ^(.*)$ http://www.mydomain.net/blog/$1 [R=301,L]
I know it's not a great idea having a directory with the same name as a static page, but I really would rather not alter the existing page and lose the Google sitelink, so a clean and proper way to handle this would be a help.
There are two things going "wrong" here, and two ways to fix it.
The first is that apache "figures out" that there is a directory by the name of "portfolio" before the rewrite conditions are applied. That means that the rewrite conditions are receiving "portfolio/" instead of "portfolio".
Second, the "!-d" rule is specifically avoiding the rewrite that you want to make if there is in fact a directory by that name
Solution 1: Manually re-route requests for the portfolio directory to remove the slash.
# Manually re-route portfolio/ requests to portfolio
RewriteCond %{REQUEST_FILENAME} portfolio/$
RewriteRule ^(.*)/$ $1
# Hide extension
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html
Note the removal of the "!-d" condition.
The downside to this is that you are having to hard-code the "portfolio" edge case directly into the rewrite rules, and will still result in the browser being first redirected to portfolio/
Solution 2: Set DirectorySlash Off and remove directory exists test
# Disable Automatic Directory detection
DirectorySlash Off
# Hide extension
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html
Setting DirectorySlash Off would fix this issue the best, but may break other parts of your site where you actually want the auto DirectorySlash. Best of Luck, and I hope this helps.
Note when testing solution 2, your browser may remember the redirect of "portfolio" to "portfolio/" and perform the redirect before it even sends the request to the server. Be sure to test in a cache-clear, clean environment for best results.

Resources