Modrewrite for subdomains using .htaccess - .htaccess

I have tried the answers in this and this but always get redirection to example.com/any. I don't understand whether I should change both htaccess files or just the inner one.
I need to redirect any.example.com to example.com?subdomain=any
This is my file structure:
/folder1
/folder2
/folder3
/web/index.php
/web/.htaccess // inner htaccess
/.htaccess // outer htaccess
Outer .htaccess:
Options -Indexes
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ web/$1 [L]
</IfModule>
# Deny accessing below extensions
<Files ~ "(.json|.lock|.git)">
Order allow,deny
Deny from all
</Files>
# Deny accessing dot files
RewriteRule (^\.|/\.) - [F]
Inner .htaccess:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^example\.com$ [NC,OR]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L]
<FilesMatch "\.(jpg|jpeg|png|gif|swf)$">
Header set Cache-Control "max-age=604800, public"
</FilesMatch>
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType application/javascript "access 1 week"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 2 days"
ExpiresByType text/x-javascript "access plus 1 month"
ExpiresByType application/javascript "access plus 1 month"
ExpiresByType application/x-javascript "access plus 1 month"
</IfModule>

Related

301 Url redirect using .htaccess

I am redirecting my old URLs to new URLs using htaccess, the URLs are not redirecting in as expected manner
htaccess
RewriteOptions inherit
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond $1 !^(index.php|resources|robots.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
Redirect 301 /testing-url /testing-link
## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType text/html "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 1 month"
</IfModule>
## EXPIRES CACHING ##
Expected output
www.example.com/testing-url from www.example.com/testing-link
but the redirected URL is redirected in the below manner
www.example.com/testing-url?/testing-link
how to override this, am using Godaddy server?

Setup prestashop htaccess file with a wordpress under a folder

My scenario es:
www.foo.com => prestashop installation
www.foo.com/blog => wordpress installation
When I visit www.foo.com/blog, wordpress works, thus, some page like www.foo.com/blog?id=[my_post_id] also works. But friend url pages don't work, for example: www.foo.com/blog/2018/09/my-wordpress-post.
I think that I need specify in .htaccess of Prestashop that use the wordpress .htaccess but i dont kwon how do that.
Any idea?
# ~~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_security.c>
SecFilterEngine Off
SecFilterScanPOST Off
</IfModule>
<IfModule mod_rewrite.c>
<IfModule mod_env.c>
SetEnv HTTP_MOD_REWRITE On
</IfModule>
RewriteEngine on
#Domain: foo.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 font/woff2 .woff2
AddType application/x-font-woff .woff
<IfModule mod_headers.c>
<FilesMatch "\.(ttf|ttc|otf|eot|woff|woff2|svg)$">
Header set Access-Control-Allow-Origin "*"
</FilesMatch>
</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"
ExpiresByType image/svg+xml "access plus 1 year"
ExpiresByType image/vnd.microsoft.icon "access plus 1 year"
ExpiresByType application/font-woff "access plus 1 year"
ExpiresByType application/x-font-woff "access plus 1 year"
ExpiresByType font/woff2 "access plus 1 year"
ExpiresByType application/vnd.ms-fontobject "access plus 1 year"
ExpiresByType font/opentype "access plus 1 year"
ExpiresByType font/ttf "access plus 1 year"
ExpiresByType font/otf "access plus 1 year"
ExpiresByType application/x-font-ttf "access plus 1 year"
ExpiresByType application/x-font-otf "access plus 1 year"
</IfModule>
<IfModule mod_headers.c>
Header unset Etag
</IfModule>
FileETag none
<IfModule mod_deflate.c>
<IfModule mod_filter.c>
AddOutputFilterByType DEFLATE text/html text/css text/javascript application/javascript application/x-javascript font/ttf application/x-font-ttf font/otf application/x-font-otf font/opentype image/svg+xml
</IfModule>
</IfModule>
#If rewrite mod isn't enabled
ErrorDocument 404 /index.php?controller=404
You must set a rewrite base in blog .htaccess file.
RewriteBase /blog/

.htaccess not redirecting website to https://www

I'm writing my redirect for my website but I can't get it to work, I have split it out so it will automatically redirect to https://www.whereshouldieat.ie, but since adding a rewrite for the index.php the redirect for the site doesn't work, and even in deleting the rewrite of the index.php it won't redirect to what I have it set to. See below what I have.
#rewrite domain name
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.whereshouldieat.ie/$1 [R,L]
#rewrite index.php
RewriteEngine On
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
## Leverage browser caching at HostPapa ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType application/x-javascript "access 1 month"
ExpiresByType application/javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 2 days"
</IfModule>
## End leverage browser caching ##
Could someone advise? I'm not sure what I'm doing wrong.
try doing this, (not tested !)
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
hope this helps.

Rewrite rule to redirect folders?

I have a set of URLs like these:
http://www.immvestwolf.de/unternehmen-2-2/uebersicht/jeden-tag-besser/
http://www.immvestwolf.de/unternehmen-2-2/team-old/architekten/
http://www.immvestwolf.de/unternehmen-2-2/uebersicht/ein-team-das-verbindet/
Now I want to redirect all URLs with /unternehmen-2-2 in the URL to the page: http://www.immvestwolf.de/unternehmen/
I tried several solutions but none worked. For example:
RewriteRule unternehmen-2-2/(.*) /unternehmen/ [L,R=301]`
Has anybody got an idea?
Full htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)/[0-9]+$ %{REQUEST_URI}/ [QSA,L,R=301]
RewriteRule ^expose/(.*)$ content/index.php?content=expose&query=$1 [L,QSA]
RewriteRule unternehmen-2-2/(.*) unternehmen/ [L,R=301]
#RewriteRule ^unternehmen/darstellung/(.*)$ content/index.php?
content=unternehmen/darstellung&query=$1 [L,QSA]
#RewriteRule ^unternehmen/team/(.*)$ content/index.php?
content=unternehmen/team&query=$1 [L,QSA]
#RewriteRule ^unternehmen/referenzen/(.*)$ content/index.php?
content=unternehmen/referenzen&query=$1 [L,QSA]
#RewriteRule ^unternehmen/partner/(.*)$ content/index.php?
content=unternehmen/partner&query=$1 [L,QSA]
#RewriteRule ^unternehmen/karriere/(.*)$ content/index.php?
content=unternehmen/karriere&query=$1 [L,QSA]
#RewriteRule ^unternehmen/verbundpartner/(.*)$ content/index.php?
content=unternehmen/verbundpartner&query=$1 [L,QSA]
#RewriteRule ^unternehmen/$ content/index.php?content=unternehmen&query=$1
[L,QSA]
#RewriteRule ^unternehmen/(.*)$ content/index.php?
content=unternehmen&query=$1 [L,QSA]
#RewriteRule ^hausverwaltung/(.*)$ content/index.php?
content=hausverwaltung&query=$1 [L,QSA]
#RewriteRule ^investment/(.*)$ content/index.php?content=investment&query=$1
[L,QSA]
#RewriteRule ^kontakt/(.*)$ content/index.php?content=kontakt&query=$1
[L,QSA]
#RewriteRule ^kontakt2/(.*)$ content/index.php?content=kontakt2&query=$1
[L,QSA]
#RewriteRule ^vermietung/angebote/(.*)$ content/index.php?
content=vermietung/angebote&query=$1 [L,QSA]
#RewriteRule ^eigentum/angebote/(.*)$ content/index.php?
content=eigentum/angebote&query=$1 [L,QSA]
#RewriteRule ^service/vermietung/(.*)$ content/index.php?
content=service/vermietung&query=$1 [L,QSA]
#RewriteRule ^service/eigentum/(.*)$ content/index.php?
content=service/eigentum&query=$1 [L,QSA]
#RewriteRule ^service/$ content/index.php?content=service&query=$1 [L,QSA]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
# PROTECT wp-config.php
<files wp-config.php>
Order deny,allow
deny from all
</files>
# PROTECT readme.html
<Files readme.html>
Order Allow,Deny
Deny from all
Satisfy all
</Files>
# PROTECT liesmich.html für DE Edition
<Files liesmich.html>
Order Allow,Deny
Deny from all
Satisfy all
</Files>
# PROTECT install.php
<Files install.php>
Order Allow,Deny
Deny from all
Satisfy all
</Files>
# Browser Cachin ON
<IfModule mod_expires.c>
ExpiresActive on
# Perhaps better to whitelist expires rules? Perhaps.
ExpiresDefault "access plus 1 month"
# cache.appcache needs re-requests
# in FF 3.6 (thx Remy ~Introducing HTML5)
ExpiresByType text/cache-manifest "access plus 0 seconds"
# Your document html
ExpiresByType text/html "access plus 0 seconds"
# Data
ExpiresByType text/xml "access plus 0 seconds"
ExpiresByType application/xml "access plus 0 seconds"
ExpiresByType application/json "access plus 0 seconds"
# RSS feed
ExpiresByType application/rss+xml "access plus 1 hour"
# Favicon (cannot be renamed)
ExpiresByType image/x-icon "access plus 1 week"
# Media: images, video, audio
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType image/jpg "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType video/ogg "access plus 1 month"
ExpiresByType audio/ogg "access plus 1 month"
ExpiresByType video/mp4 "access plus 1 month"
ExpiresByType video/webm "access plus 1 month"
# HTC files (css3pie)
ExpiresByType text/x-component "access plus 1 month"
# Webfonts
ExpiresByType font/truetype "access plus 1 month"
ExpiresByType font/opentype "access plus 1 month"
ExpiresByType application/x-font-woff "access plus 1 month"
ExpiresByType image/svg+xml "access plus 1 month"
ExpiresByType application/vnd.ms-fontobject "access plus 1 month"
# CSS and JavaScript
ExpiresByType text/css "access plus 1 year"
ExpiresByType application/javascript "access plus 1 year"
ExpiresByType text/javascript "access plus 1 year"
<IfModule mod_headers.c>
Header append Cache-Control "public"
</IfModule>
</IfModule>
# Deflate Compression by MimeType
<IfModule mod_deflate.c>
<FilesMatch "\.(js|jpg|jpeg|gif|png|css)$">
ExpiresActive on
ExpiresDefault "access plus 1 month"
SetOutputFilter DEFLATE
</FilesMatch>
</IfModule>
#Schnittstelle xmlrpc sperren
<FilesMatch "(\.htaccess|\.htpasswd|wp-
config\.php|liesmich\.html|readme\.html|xmlrpc\.php)$">
order deny,allow
deny from all
</FilesMatch>`

.htaccess making a fake subfolder after main domain

I want/need to rewrite all my product urls
for example a product url in three languages.
mainurl.com/en/outdoor/wood-table
mainurl.com/de/außenbereich/holz-tisch
mainurl.com/it/esterno/tavolo-legno
What url i want/need is:
mainurl.com/products/en/outdoor/wood-table
mainurl.com/products/de/außenbereich/holz-tisch
mainurl.com/products/it/esterno/tavolo-legno
Running the Shop Local with xampp in the Root-Folder htdocs.
How can i rewrite this url via .htaccess and making this fake subfolder after the mainurl?
This is the original .htaccess file that is included in the Shopsystem xt:commerce:
# RewriteEngine on
# RewriteRule !\.(js|ico|gif|jpg|png|css)$ index.php
DirectoryIndex index.php
<IfModule mod_rewrite.c>
SetEnv HTTP_MOD_REWRITE On
Options -MultiViews
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/media/
RewriteCond %{REQUEST_URI} !^/xtAdmin/
RewriteCond %{REQUEST_URI} !^/skin/
RewriteCond %{REQUEST_URI} !^/js/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule .* index.php
</IfModule>
<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 1 seconds"
ExpiresByType image/x-icon "access plus 2692000 seconds"
ExpiresByType image/jpeg "access plus 2692000 seconds"
ExpiresByType image/png "access plus 2692000 seconds"
ExpiresByType image/gif "access plus 2692000 seconds"
ExpiresByType application/x-shockwave-flash "access plus 2692000 seconds"
ExpiresByType text/css "access plus 2692000 seconds"
ExpiresByType text/javascript "access plus 2692000 seconds"
ExpiresByType application/x-javascript "access plus 2692000 seconds"
</IfModule>
<IfModule mod_headers.c>
<FilesMatch "\\.(ico|jpe?g|png|gif|swf|css|js)$">
Header set Cache-Control "max-age=2692000, public"
</FilesMatch>
Header unset ETag
Header unset Last-Modified
</IfModule>
Insert this rule just below RewriteEngine on:
RewriteRule ^product/(.*) $1 [L,NC]

Resources