MODx & .htaccess issue - .htaccess

I have been trying to get FURLs working in MODx. Following resource covers this topic in details - http://rtfm.modx.com/display/revolution20/Using+Friendly+URLs. However once the changes to .htaccess are made, the site is no longer available. Here is my .htaccess file:
# Friendly URLs Part
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} .
# Force all pages to go to www.domain.com for SEO
RewriteCond %{HTTP_HOST} !^www\.dev\.domain\.co\.uk [NC]
RewriteRule (.*) http://www.dev.domain.co.uk/$1 [R=301,L]
# Friendly URLs
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
# Additional Settings Follow
ExpiresActive On
ExpiresByType image/gif A2592000
ExpiresByType image/jpeg A2592000
ExpiresByType image/png A2592000
BrowserMatch "MSIE" brokenvary=1
BrowserMatch "Mozilla/4.[0-9]{2}" brokenvary=1
BrowserMatch "Opera" !brokenvary
SetEnvIf brokenvary 1 force-no-vary
Any ideas what may be the issue?

Change .htaccess back to original - https://github.com/modxcms/revolution/blob/develop/ht.access

Try this Default htaccess file for modx
RewriteEngine On
RewriteBase /
#RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\.example.com [NC]
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
# Rewrite secure requests properly to prevent SSL cert warnings, e.g. prevent
# https://www.example.com when your cert only allows https://secure.example.com
#RewriteCond %{SERVER_PORT} !^443
#RewriteRule (.*) https://example.com/$1 [R=301,L]
# The Friendly URLs part
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
Check this for full htaccess file

Related

PRESTASHOP 1.7 || How to configure Friendly Url with some parameters on CSM customized page?

I have created a custom CMS page on Prestashop, I need to use some parameters to show some information about products. I need it to be friendly though.
The webpage is already configured to be SEO friendly, each new CMS page I create get to has it's own friendly URL, but I need to get the parameter between slashes.
Example:
This is what I got now == prestashopstore.com/items?type=foo
This is what I want == prestashopstore.com/items/foo
This is for the last version of Prestashop
Any ideas? Many thanks for the help.
PD. This is my .htaccess
Options +FollowSymLinks
# ~~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:Authorization} ^(.*)
RewriteRule . - [E=HTTP_AUTHORIZATION:%1]
#Domain: domain.com
RewriteRule . - [E=REWRITEBASE:/]
RewriteRule ^api$ api/ [L]
RewriteRule ^api/(.*)$ %{ENV:REWRITEBASE}webservice/dispatcher.php?url=$1 [QSA,L]
# Images
RewriteRule ^([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$1$2$3.jpg [L]
RewriteRule ^([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$1$2$3$4.jpg [L]
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]
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]
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]
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]
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]
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]
RewriteRule ^c/([0-9]+)(\-[\.*_a-zA-Z0-9-]*)(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/c/$1$2$3.jpg [L]
RewriteRule ^c/([a-zA-Z_-]+)(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/c/$1$2.jpg [L]
# AlphaImageLoader for IE and fancybox
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
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ %{ENV:REWRITEBASE}index.php [NC,L]
</IfModule>
AddType application/vnd.ms-fontobject .eot
AddType font/ttf .ttf
AddType font/otf .otf
AddType application/font-woff .woff
AddType font/woff2 .woff2
<IfModule mod_headers.c>
<FilesMatch "\.(ttf|ttc|otf|eot|woff|woff2|svg)$">
Header set Access-Control-Allow-Origin "*"
</FilesMatch>
</IfModule>
#If rewrite mod isn't enabled
ErrorDocument 404 /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
Try with htacces rules :
<IfModule mod_rewrite.c>
<IfModule mod_env.c>
SetEnv HTTP_MOD_REWRITE On
</IfModule>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/([^/]*)? $1?type=$2 [NC,N,QSA]
</IfModule>
Regards

Redirection issue in htaccess

I have one issue with my htaccess redirection code.
Suppose I request this url
https://example.com/about-us/
Then its redirect to non-slash link that means they redirect to
https://example.com/about-us
but what happens in between
https://example.com/about-us/ this url redirect to
https://example.com/about-us.html then redirect to
https://example.com/about-us
I want to remove this middle step from redirection.
I attached my htaccess code for better understanding
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} !=on
# This checks to make sure the connection is not already HTTPS
RewriteCond %{HTTP_USER_AGENT} !Twitterbot [NC]
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
#RewriteCond %{HTTP_USER_AGENT} !Twitterbot [NC]
RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]
RewriteBase /
RewriteCond %{REQUEST_FILENAME} "blog"
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} "blog"
RewriteRule . /index.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#RewriteCond %{REQUEST_FILENAME}\.html -f
# remove the .html extension
RewriteCond %{THE_REQUEST} ^GET\ (.*)\.html\ HTTP
RewriteRule (.*)\.html$ $1 [R=301]
# remove trailing slash if not a directory
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} /$
RewriteRule (.*)/ $1 [R=301]
# forward request to html file, **but don't redirect (bot friendly)**
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule (.*) $1\.html [L]
</IfModule>
#Alternate default index page
DirectoryIndex index.html
## 404 Page
ErrorDocument 404 https://example.com/404
## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/gif "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType text/css "access plus 1 month"
ExpiresByType application/pdf "access plus 1 month"
ExpiresByType text/x-javascript "access plus 1 month"
ExpiresByType application/x-shockwave-flash "access plus 1 month"
ExpiresByType image/x-icon "access plus 1 year"
#ExpiresDefault "access plus 2 days"
</IfModule>
## EXPIRES CACHING ##
# END WordPress
Thank you in advance
Keep all your redirect rules at top:
Options -MultiViews
RewriteEngine On
RewriteBase /
## remove www and turn on https in same rule
RewriteCond %{HTTP_HOST} ^www\. [NC,OR]
RewriteCond %{HTTPS} !on
RewriteCond %{HTTP_USER_AGENT} !Twitterbot [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [R=301,L,NE]
# remove the .html extension
RewriteCond %{THE_REQUEST} ^GET\ (\S+)\.html\ HTTP [NC]
RewriteRule ^ %1 [R=301,L,NE]
# remove trailing slash if not a directory
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^(.+)/+$
RewriteRule ^ %1 [R=301,NE,L]
# forward request to html file, **but don't redirect (bot friendly)**
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule ^ %{REQUEST_URI}.html [L]
# remaining rules go below this
Make sure to use a new browser for your testing or completely clear your browser cache.
About Options -MultiViews: Option MultiViews (see http://httpd.apache.org/docs/2.4/content-negotiation.html) is used by Apache's content negotiation module that runs before mod_rewrite and makes Apache server match extensions of files. So if /file is the URL then Apache will serve /file.html.

HTTP to HTTPS clean redirect

I have been searching the net and this website too and following some suggestions I managed to get it limping but it's still not perfect.
Here is the problem. When someone is accessing my website using plain HTTP, it redirects them to HTTPS but the url looks like this https://www.domain.com/index.php?rewrite=1
That is ugly alright but that's not the biggest issue here. The problem is that when members of the website try to log in, after filling out the details and click sign in, the page reloads to https://www.domain.com/ blanks the log-in fields. Typing in the info again and click sign in, member can log in on this second attempt. It becomes frustrating to those that access the website with plain http until they figure out that they want to use https instead.
However I would like to fix this problem and I ask your help for it.
Here is my current .htaccess file, I know that there is something very simple to change but I can't spot it.
Thank you!
IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{HTTP:X-Forwarded-Proto} =http
RewriteCond %{HTTP_USER_AGENT} !(SEAOSEAPP)
RewriteRule . https://%{HTTP:Host}%{REQUEST_URI} [L,R=permanent]
# Get rid of index.php
RewriteCond %{REQUEST_URI} /index\.php
RewriteRule (.*) index.php?rewrite=2 [L,QSA]
# Rewrite all directory-looking urls
RewriteCond %{REQUEST_URI} /$
RewriteRule (.*) index.php?rewrite=1 [L,QSA]
# Try to route missing files
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} public\/ [OR]
RewriteCond %{REQUEST_FILENAME} \. (jpg|gif|png|ico|flv|htm|html|php|css|js)$
RewriteRule . - [L]
# If the file doesn't exist, rewrite to index
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?rewrite=1 [L,QSA]
</IfModule>
# sends requests /index.php/path/to/module/ to "index.php"
# AcceptPathInfo On
# #todo This may not be effective in some cases
FileETag Size
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript
</IfModule>

.htaccess add tablet redirect

Using the .htaccess file, I wish to redirect tablet traffic to a tablet optimised site.
Regular URL: waxxxed.com.au
Tablet Optimised URL: waxxxed.com.au/tablet/
I've tried the following code but it doesn't work.
RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} ipad [NC]
RewriteCond %{HTTP_HOST} !^ipad\. [NC]
RewriteRule ^ http://waxxxed.com.au/tablet/ [L,R=301]
x3 questions...
This code doesn't work. Appears to create a loop. Not sure, but that may be related to my existing .htaccess code provided below.
I want to redirect ALL tablets (not mobiles) not just iPads. How do I capture other tablet brands?
Can you recommend any further optimisation of my .htaccess coding.
Full current .htaccess file (it works!)...
<IfModule mod_expires.c>
# Enable cache expirations
ExpiresActive On
# Default directive
ExpiresDefault "access plus 1 month"
# My favicon
ExpiresByType image/x-icon "access plus 1 year”
</IfModule>
# force redirect of html to no-extension
RewriteCond %{THE_REQUEST} ^GET\s.+\.html
RewriteRule ^(([^/]+/)*[^/.]+)\.html$ http://waxxxed.com.au/$1 [R=301,L]
# www to non-www
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.waxxxed.com.au
RewriteRule (.*) http://waxxxed.com.au/$1 [R=301,L]
# Redirect from / to non-/
RewriteEngine On
RewriteRule ^(.*)/$ $1 [R=301,NC,L]
# parse file as file.html
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(([^/]+/)*[^/.]+)$ $1.html [L]
# refer not found content to 404 page
ErrorDocument 404 /404page.html
The reason why it creates a loop is because you're checking that the hostname doesn't start with ipad, and since you're redirecting to waxxxed.com.au, it's never going to start with ipad. Instead check for the request URI starting with /tablet/:
RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} ipad [NC]
RewriteCond %{REQUEST_URI} !^/tablet/. [NC]
RewriteRule ^ http://waxxxed.com.au/tablet/ [L,R=301]
As for #2, you need to lookup user-agents for other tablets. In general, you want to find "android" but not "mobile":
RewriteCond %{HTTP_USER_AGENT} android [NC]
RewriteCond %{HTTP_USER_AGENT} !mobile [NC]
RewriteCond %{REQUEST_URI} !^/tablet/. [NC]
RewriteRule ^ http://waxxxed.com.au/tablet/ [L,R=301]
The rest of your htaccess file looks fine as long as it's doing what you expect, anything would be really nit-picky.

301 redirect with .htaccess does not work

I am trying to setup following redirection:
From: http://www.contractorshire.co.uk/plant/attachments.asp
To: http://www.contractorshire.co.uk/catalog/plant/attachments/
Following entry in .htaccess does not work:
Redirect 301 /plant/attachments.asp /catalog/plant/attachments/
Any ideas why?
LG
Full .htaccess:
# Friendly URLs Part
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} .
# Force all pages to go to www.domain.com for SEO
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule (.*) http://www.%{HTTP_HOST}/$1 [R=301,L]
# Friendly URLs
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
# ASP Redirects
RewriteRule ^plant/attachments\.asp$ catalog/plant/attachments/[R=302,L]
# Additional Settings Follow
ExpiresActive On
ExpiresByType image/gif A2592000
ExpiresByType image/jpeg A2592000
ExpiresByType image/png A2592000
BrowserMatch "MSIE" brokenvary=1
BrowserMatch "Mozilla/4.[0-9]{2}" brokenvary=1
BrowserMatch "Opera" !brokenvary
SetEnvIf brokenvary 1 force-no-vary
I see quite a few people have problems with this method. Most resort to using mod_rewrite:
RewriteEngine On
RewriteBase /
RewriteRule ^plant/attachments\.asp$ catalog/plant/attachements/ [R=301,L]
Alternatively, I think that Redirect requires an absolute destination path:
Redirect 301 /plant/attachments.asp http://contractorshire.co.uk/catalog/plant/attachments/

Resources