How do I redirect specific file extensions from one directory (that no longer exists) to another? - redirect

We have just moved to a new site structure and some of our old directories no longer exist. Our old directory /html/ held both .jpg and .pdf files. Those files have now been moved into their own directories ( /images/ and /documents/ respectively).
How can I use the root .htaccess file to redirect all links that were pointing to the /html/ directory for .pdf and .jpg files to the current /documents/ and /images/ directory?
In other words, if a link comes in for www.example.com/html/.pdf I would like it to be directed to www.example.com/documents/.pdf.
Likewise for .jpg requests, if a link comes in for www.example.com/html/.jpg I would like it to be redirected to www.example.com/images/.jpg.
I have tried several different rewrite rules from this site but I can't seem to adjust the syntax to my exact needs.
I'm currently trying to use this type of code:
RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteRule ^html/*.pdf$ "https://www.example.com/documents/$1" [L,R=301]

Check this rewrites in your .htaccess file
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^html\/(.*)\.pdf$ https://www.example.com/documents/$1.pdf [R=301,L]
RewriteRule ^html\/(.*)\.jpg$ https://www.example.com/images/$1.jpg [R=301,L]

Related

Backlink from Instagram throws 404, Need it to correctly redirect to root url instead

My self-coded portfolio website is giving me problems when used as an Instagram profile link (let's say www.myurl.com): the Instagram browser displays a 404 error when clicking the profile link. Clicking "Back to Index" on the 404 page shows the website as it should. After checking the URL, I see that Instagram automatically adds a random string to the domain (like www.myurl.com/?fbclid=PAAaa-Vm9q.../) and I assume my website doesn't know how to redirect this. The issue does not occur on a desktop computer, only mobile.
I'm guessing this random string is an SEO tool, which I woefully do not know how to use.
But I need the website link on IG to go through to my homepage without throwing the 404 error, at a minimum. Is there some kind of code / html document / web hosting / dns setting I need to manipulate to get this to work?
I have a feeling this is an issue caused by DNS settings on Cloudflare since I recently set up a proxy with them to use their global SSL certificate.
Some notes about my website in case they are helpful:
hosting on GoDaddy, recently proxied through CloudFlare for SSL certificate
I have the main domain (www.myurl.com) automatically redirect to a subdomain (sub.myurl.com). This subdomain is actually stored in a folder like www.myurl.com/sub/ .
Website is a CMS built on PHP 5
I tried URL shortener services as a stopgap measure. The only one that solved the problem was shorturl.at, but tiny.url and bit.ly still had the 404 issue. I have no idea why.
I looked at the htaccess document in the subdomain root folder, the contents are below. I think the issue may be that the "base" needs to be "rewritten" to the subfolder (www.myurl.com/sub/) but I'm not sure how to correctly change this code:
RewriteEngine on
# Some hosts require a rewritebase rule, if so, uncomment the RewriteBase line below. If you are running from a subdirectory, your rewritebase should match the name of the path to where stacey is stored.
# ie. if in a folder named 'stacey', RewriteBase /stacey
#RewriteBase /
ErrorDocument 404 /404.html
# Rewrite any calls to *.html, *.json, *.xml, *.atom, *.rss, *.rdf or *.txt if a folder matching * exists
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !public/
RewriteCond %{DOCUMENT_ROOT}/public/$1.$2 !-f
RewriteRule (.+)\.(html|json|xml|atom|rss|rdf|txt)$ $1/ [L]
# Add a trailing slash to directories
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.)
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ([^/]+)$ $1/ [L]
# Rewrite any calls to /* or /app to the index.php file
RewriteCond %{REQUEST_URI} /app/$
RewriteRule ^app/ index.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ index.php?$1 [L]
# Rewrite any file calls to the public directory
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !public/
RewriteRule ^(.+)$ public/$1 [L]
I'm very much a beginner with webhosting / coding / etc so will appreciate an idiot-friendly explanation!! Thanks in advance.

TYPO3 fileadmin directory shows all files of all pages in browser

I do expirience the following problem.
I do have a TYPO3 v7.6 CMS with multiple websites.
The problem is, that all files are visible in fileadmin if written in URL
For example PDF File with link
www.webpage-one.com/fileadmin/webpage-one/documents/pdffile
will be opened in browser if you type another URL of a webpage inside the same TYPO3 Instance.
www.webpage-two.com/fileadmin/webpage-two/documents/pdffile
Anyone with expirience on the matter?
Cheers
If you're using Apache (or another webserver that supports .htaccess and mod_rewrite) you can add a .htaccess file to the different directories in fileadmin with the following:
RewriteEngine On
RewriteCond %{HTTP_HOST} !webpage-one.com$ [NC]
RewriteRule ^ - [L,F]
This will make this directory only accessible from domains containing webpage-one.com. Other domains will get a 403 Forbidden error.
If it should only work for www.webpage-one.com (so not without www), you should change the RewriteCond line to:
RewriteCond %{HTTP_HOST} !^www.webpage-one.com$ [NC]
If it should work both with and without www, but not on other subdomains, you should use 2 RewriteCond lines:
RewriteCond %{HTTP_HOST} !^webpage-one.com$ [NC]
RewriteCond %{HTTP_HOST} !^www.webpage-one.com$ [NC]

css and js files are not loaded with multiple .htaccess slimframework

well i have setup slim skeleton directly in public_html where in that directory their is first .htaccess file contain routing to public folder.
first .htaccess contain:
RewriteEngine On
RewriteBase /public/
RewriteRule ^$ public/
due to which my domain is directly pointing to public/index.php
which contain second .htaccess file with slimframework standard .htaccess file:
RewriteEngine On
# Some hosts may require you to use the `RewriteBase` directive.
# If you need to use the `RewriteBase` directive, it should be the
# absolute physical path to the directory that contains this htaccess file.
#
# RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [QSA,L]
Because of this my css and js files are not loaded inside template and they are going as in console
GET http://domain.com/css/bootstrap.min.css
returning 404 error
I am struugling with this issue from two days but still not able to get where should i change as its working fine on my local server but not over godaddy server.

Deploying Laravel to Bluehost

I was wondering if anyone has had any experience deploying larval to blue host? I was flowing an youtube tutorial that showed how to deploy a larval application to a shared hosting service. It was using Godaddy.com, however, i was using Bluehost, and it didn't work as expected. However I managed to getting to not return an internal server error.
What I did was to configure the .env file so that it had my correct database information and my APP_URL to point to my domain.
The youtube tutorial said I should also remove everything from the public folder and place it in the applications main folder, which on Bluehost is the public_html folder. I also changed the .htaccess and removed the public in the rewrite that handles the redirects for trailing slashed.
Now, when I point to my website, all that is served up is a blank screen. but something seems to be working because I uploaded an html webpage that renders to the browser. I just wondering where do I go from here to get the entire site running.
i'm using php 5.6.
Any help would be great. Thank you
I think you are using shared hosting
Follow these steps
1: After upload files to public_html move all your /public files in public_html folder All files like index.php, .htaccess and assets folder etc
2: Find the following line in index.php
require __DIR__.’/../bootstrap/autoload.php’;
require __DIR__.’/../project/bootstrap/autoload.php’;
change to
require __DIR__.’/bootstrap/autoload.php’;
require __DIR__.’/project/bootstrap/autoload.php’;
That’s it. Well then, have fun.
check that the PHP version is correct for Laravel
in cPanle enable FastCGI for PHP
open file .htaccess located in /public and edit
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteBase /public/
# For security reasons, Option followsymlinks cannot be overridden.
# Options +FollowSymLinks
Options +SymLinksIfOwnerMatch
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
This is my .htaccess codes which are different in different server.
#Default Setup
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php72” package as the default “PHP” programming language.
<IfModule mime_module>
AddHandler application/x-httpd-ea-php72 .php .php7 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit
//bluehost------------
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
RewriteBase /
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

zend framework deployment in server

I have a server, where I have uploaded my work in zend framework(in a subdomain). the folder name is 'visit'.
So, When I go to: http://mysitename.com/visit, it shows a directory structure:
Parent Directory
application/
docs/
library/
nbproject/
public/
tests/
But when I go to: http://mysitename.com/visit/public, i get the index page of my project.
But I want to get my index page , when I type: http://mysitename.com/visit
can you please give me the correct htaccess it need?
Also, these other approaches to deploying in shared hosting can help:
Zend Framework on shared hosting
http://www.alberton.info/zend_framework_mod_rewrite_shared_hosting.html
http://akrabat.com/zend-framework/zend-framework-on-a-shared-host/
http://www.ttech.it/en/article/2010/03/zend-framework-all-projects-files-on-document-root/
In particular, an answer by tharkun led me to write it up in more detail in a blog post.
You can do this with the following rule set, which is in part a partially modified version of the one described in the documentation.
.htaccess file in /visit:
RewriteEngine on
# Guard against people visiting /public/ directly
RewriteCond %{THE_REQUEST} ^[A-Z]\s/visit/public/
RewriteRule ^public/(.*)$ /visit/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
# Make sure we've rewritten to the ./public/ directory already
RewriteCond $0 ^public/
RewriteRule ^.*$ - [NC,L]
# The index file is now at /visit/public/index.php
RewriteRule ^.*$ /visit/public/index.php [NC,L]