Mask folder name and show only subdirectory - .htaccess

I have this structure:
http://mywebsite.com/folder/myapp1
http://mywebsite.com/folder/myapp2
http://mywebsite.com/folder/myapp3
How can I do to hide "folder" in the URL using .htaccess?
That is, if I enter
http://mywebsite.com/myapp1
I want it to display the contents of
http://mywebsite.com/folder/myapp1
Thanks in advance!

You can try this. This should work for you inyour .htaccess file.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+) folder/$1 [L]

Related

Point to a file in subfolder with .htaccess

I've wanted to move my index.php file from the root to /system/ folder, this is for no reason but giving myself opporunity to learn more about .htaccess, which I am finding very confusing.
How can I achieve this? Currently my code looks as follows
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?query=$1
This allows for example mydomain.com/some-url/ to become /index.php?query=some-url for example, this far I'm with it all. But moving the file into System folder and addind /system/ before /index.php does nothing. How does one do this? Thanks!
This could be done with a simple rewriterule. Please make sure you clear your browser cache before testing your URLs.
RewriteEngine ON
RewriteCond %{REQUEST_URI} ^/?$
RewriteRule ^(.*)$ system/index.php [L]

how to ignore index.php file from urlrewrite

This is my simple htaccess code:
RewriteRule ^books/([A-Za-z0-9.]+)$ library/search.php?zig=$1 [NC,L]
My code is working fine for the followings:
mydomain/books/math
mydomain/books/english
mydomain/books/physics.applied
as
library/search.php?zig=math
library/search.php?zig=english
library/search.php?zig=physics.applied
But my code is not working only for
mydomain/books/
it is acting as
library/search.php?zig=index.php
There is no subject named index.php. I want to remove this index.php. My search function should not work for mydomain/books/
You can add a RewriteCond to ignore all files and directories from rewrite:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^books/([A-Za-z0-9.]+)$ library/search.php?zig=$1 [NC,L,QSA]

Removing 2 directory and php from url

My current url is:
http://example.org/dir1/dir2/profile.php?username=someone
I want it to look like this:
http://example.com/someone
My .htaccess file is in public_html folder and it is completely empty.
Please, can you help me?
Try this :
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([a-zA-Z0-9_-]+)/?$ /dir1/dir2/profile.php?username=$1 [QSA,L,NC]
The conditions make sure you don't rewrite any existing file/directories on the server.

.htaccess file and folder with the same name

I am new at .htaccess and I have a PHP file called products.php and a folder with the same name called /products.
I want to create a friendly URL for the products page of my website a I would like to know if it is possible to execute the products.php file outside the folder /products.
I am using the .htaccess code below.
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^products/([a-z0-9-]+)/([0-9]+)/?$ products.php?id=$2&nome=$1 [NC]
Thanks
Did you try it and it didn't work ? if it didn't, try removing this line :
RewriteCond %{SCRIPT_FILENAME} !-d

htaccess get filename without path

I'm trying to get the requested filename without the path with htaccess for a RewriteCond.
REQUEST_FILENAME returns the full absolute path, but I only need the filename like test.php
I've been searching for this a lot but couldn't find anything that helped me out.
Thanks for any responses in advance!
Edit:
Im trying to do something like this:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond _%{REQUEST_FILENAME}.php -f
RewriteRule ^([^/]*)$ _$1.php [L]
The URL typed in the browser looks like this: http://example.org/test
The File that will be requestested by the RewriteRule is: http://example.org/_test.php
With RewriteCond _%{REQUEST_FILENAME}.php -f i tried to check if the file exists first
Basically I want to do this:
URI: /test/blah
Check if _test.php exists (with underscore!)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/_$1.php -f
RewriteRule ^([^/]+)$ _$1.php [L]
I changed * to + so requests for e.g. example.com/ will not redirect to _.php

Resources