htaccess to fix broken links on local site - .htaccess

So after moving a live site onto a local computer for offline show casing, a lot of the links have broken because of missplaced ../ that dreamweaver puts in.
It works online because the user of that domain doesn't have permission to leave it's doc root, but not so locally.
Is there an .htaccess that I could put the root dir that would restrict or redirect back to itself when trying to navigate to it's parent?
So the site is in xampp/mysite/ and an img src has a value of ../images/image.png
So it's looking for the image at xampp/images/image.png instead of staying in it's root dir of xampp/mysite/images/image.png

I am assuming that all of your images are in the /xampp/mysite/images directory.
If so, then you could try adding the following to your .htaccess file in the root directory of your site.
RewriteEngine on
RewriteBase /
#if request is not in xampp/mysite/images/
RewriteCond %{REQUEST_URI} !^/xampp/mysite/images/ [NC]
#rewrite images to /xampp/mysite/images
RewriteRule /(.+\\.(png|jpg|gif))$ /xampp/mysite/images/$1 [NC,L]

Related

Redirect existing second page to non-existing url

I have a site https://sitename.com/web (example). So, full path to page is sitename.com/web/index.php. On ftp server there is folder /web which also contain second page file - index-2.php. How to avoid creating /web-2/ folder and redirect index-2.php to sitename.com/web-2 ?
Easy, create an .htaccess file inside the root folder of your site, then add the following lines to it:
RewriteEngine On
RewriteRule ^web-2$ index-2.php [QSA,L,NC]
This site might help you with htaccess:
https://www.htaccessredirect.net/
A nice tutorial on .htaccess files also below:
https://www.digitalocean.com/community/tutorials/how-to-use-the-htaccess-file

.htaccess url redirect from one an old page to a new one keeping the root directory same

I have an application whose codebase is deployed inside a folder shop . The URL to the main application is http://myapp/shop/.
One of the links on my page reads
http://myapp/shop/website-design/design-urself.php
which I want to redirect to http://myapp/shop/website-design/index.php
The rule which I am using in my .htaccess file is :
RewriteEngine On
RewriteBase /
RewriteRule ^/website-design/design-urself.php /website-design/index.php [R=301]
But the link is wrongly being getting redirected to http://myapp/website-design/index.php
I tried by removing the leading slash (/) from the urls as :
RewriteRule ^website-design/design-urself.php website-design/index.php [R=301]
but still it doesn't work.
I can understand that probably changing the RewriteBase to shop will solve my problem.
However , the thing here is - going further, the folder name ("shop" in my case) can change . So , in that case I have to again go and modify the .htaccess , which is not desirable.
What is the appropriate RewriteRule I should use in this case?
UPDATE : I have my .htaccess file located at my document root , i.e, inside the folder shop and outside of all other folders residing inside shop.

.htaccess redirect subfolder but don't show subfolder in address bar

I have a folder in my public_html directory named landingPages which obviously holds all our Landing Pages.
The problem is all the URLs on Google AdWords etc. are set to the public_html folder, for example:
http://www.example.com/landingPage1.php
Putting all the files in the new landingPages directory was done to clear up the public_html directory and seperate everything a bit but changing all the URLs is something we want to avoid.
I want that if you go to to http://www.example.com/landingPage1.php in the browser that it actually loads whats inside the landingPages folder so it calls http://www.example.com/landingPages/landingPage1.php in the background.
I have tried a few things but can't seem to find a catch all version to determine if whatever is requested in the browser is present in the landingPages folder and if so to re-direct or if this sort of catch all request is at all possible.
If not, I guess I would have to manually create rules for each file I want re-directed including any future created Landing Pages which is what I am trying to avoid here.
put this code in your .htaccess under the website root directory, this will check if the file exists in landingPages folder, if so, it will load the content of that file.
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}/landingPages/$1 -f [NC]
RewriteRule ^([^/]+)$ /landingPages/$1 [L,QSA]

Installing codeigniter in a subfolder and point to the main site?

I'm trying install my codeigniter application in a sub folder: http://website.com/sub_folder
And I want that this site is accessible through: http://website.com/
I have the following info in my application/config.php file for the base url: $config['base_url'] = 'http://website.com/sub_folder';
This is my .htaccess:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|captcha|assets|favicon\.gif|robots\.txt)
RewriteRule ^(.*)$ /sub_folder/index.php/$1 [L]
The problem is that when I change the $config['base_url'] to access my asset files, like css etc al my other links using $base_url() point to : http://website.com/sub_folder too instead of http://website.com/
If I understand what you want to achieve, you're doing it wrong, simply place index.php file in your root folder and your application to the sub-folder.
Change system and application paths in index.php to where exactly they are located and you're done.
$system_path = 'subfolder/system';
$application_folder = 'subfolder/applications';
In any case, if it's possible, consider moving application and system folders out of the root directory as it will cover hundreds of potential security holes.

.htaccess - How to hide the internal directory used by subdomains?

I installed a small FTP space for my classmates which allows them to upload school related documents to my server. After the files have been uploaded, they can be easily accessed via a subdomain i.e. ftp.mydomain.com
Everything is working fine, the files can be downloaded and everything works properly.
There are two things which still annoy me though:
If you enter ftp.mydomain.com you see Index of /my_internal_directory instead of something like Index of /
Once you enter a sub-directory and click the Parent Directory link it will redirect you to ftp.mydomain.com/my_internal_directory/ as well
Is there any way to hide my_internal_directory ?
This is the content of my .htaccess file so far:
RewriteEngine on
RewriteCond %{HTTP_HOST} ftp\.mydomain\.com
RewriteCond %{REQUEST_URI} !^/my_internal_directory/
RewriteRule ^(.*)$ /my_internal_directory/$1 [L]
Any help would be greatly appreciated.
If you are using linux server then you can remove read permission for folder my_internal_directory
If not resolve, try to add:
Options -Indexes
on top of the file.
If still doesnt resolve please post your .htaccess file... :)

Resources