Remove a specific file name using from url and subdirectory - .htaccess

My site url is like
https://website.com/folder1/folder2/file111.php
I want to rewrite that url to
https://website.com/folder2/
i want to remove specific file name (file111.php) with extension and remove subdirectory folder2
i found solution on the site but didn't work with me

Related

Redirecting folder to file download within same folder

I want my user to type in a simple URL with a folder name and have automatically download a file. For example:
example.com/file would redirect them to example.com/file/text.ext. One way I thought I could do it is using .htaccess file, sadly that generates too many redirect errors. My code was:
Redirect 301 /file /file/text.ext
What gives?
This is because your Redirect pattern /file also matches the destination path /file/text.ext . You need to make it so that it doesn't match the target path. You can use RedirectMatch that only matches the /file path
RedirectMatch 301 ^/file/?$ /file/text.ext
Make sure to clean your browser cache or use a different browser to test this change.

how to remove particular folder name from URL using htaccess

I have an URL :
http://localhost/HeapShop/admin/pages/create-users.php/
I need to change this URL to :
https://localhost/heapshop/admin/create-users.php/
Need to remove pages (Folder Path) from URL.

Is there a way force a url to open up a specified file using .htacess

I don't know if this counts as a redirect, but I need all url's that start with a to open up the index.html in their first directory. Meaning website.com/blog and website.com/blog/3 both use website.com/explore/.index.html file, while website.com/albums, website.com/albums/john-smith, and website.com/albums/john-smith/4 all use website.com/albulms/index.html
Is there anyway to make the index.html files load without changing the redirect of the url itself?

Redirect localhost subaddress to another folder

My "htdocs" folder is set to this: C:\webserver\xampp\htdocs
All my folders exist in subfolders of this folder.
I have such another folder here: c:\MyProjects\project1
I need to htaccess rewrite so, when I write: http://127.0.0.1/project1/myfile.php
On my browser, I will see the result of "myfile.php" inside "project1" folder.
Is it possible?
Is it possible?
No, you can't rewrite a URI outside of your document root, C:\webserver\xampp\htdocs. And htaccess file sitting in that htdocs directory won't be able to point a request outside of the htdocs directory. Mod_rewrite isn't what you want anyways. You want to use mod_alias from within the vhost config or server config. Something along the lines of:
Alias /project1 C:/MyProjects/project1
See also: Make XAMPP/Apache serve file outside of htdocs

mod_rewrite / .htaccess - domain name showing twice in URL

I have an "addon domain" with no specified htaccess file but the main site (of which the add on site is a sub dir) DOES have htaccess which rewrites url to remove the .html prefix.
Anyhow when i go to the addon domain for instance: test.com/about.html it automatically changes to test.com/test.com/about.html
Can anyone point me in the direction to correct this?
If there is no htaccess file with modRewrite in it in a directory, apache goes up to the parent directory to search for it, and this goes up along the tree (this is not affected by having an addon domain or not). So that means that your addon domain is affected by the htaccess file of the parent domain.
What you need to do is create an htaccess file in the subdirectory (the addon domain) and desactivate rewriting :
RewriteEngine Off
Or you can add your own RewriteRules if you want.

Resources