How to check non index directory using htaccess - php

I want to redirect to the main domain if a directory(any) exists
but does not have an index file(index.php/index.html), How to do that? I tried the below code but does not work.
Options +FollowSymlinks -Indexes
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ %1 [R=301,L]

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{DOCUMENT_ROOT}/$1/index.php !-f [OR]
RewriteCond %{DOCUMENT_ROOT}/$1/index.html !-f
RewriteRule ^(.+)/$ / [L,R]
This will redirect a directory request to / if the /index file doesn't exist in that folder.

Related

htaccess https://example.com/dash/something link redirect problem

I have some directories:
/
/dash
/something
I want to make htaccess to redirect all traffic to it's subfolder index.php , which i did, when i type it works
example.com/dash or example.com/something
But my problem is when i try something like this example.com/dash/login or example.com/dash/another
in this case i'm redirected to / directory
Here is my htaccess in / directory
https:// we.tl/t-NtTDlYKBHr
Options -Indexes -MultiViews +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(?!dash/)(.+)$ /index.php?u=$1 [NC,QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^dash/(.+)$ /dash/index.php?u=$1 [NC,QSA,L]
And in /dash
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?path=$1 [NC,L,QSA]
https:// we.tl/t-lhgQ03tTGE
I am not expert on this. but I think you achieve it by something like this.
put this file in your parent directory
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^none/ none/index.php [NC,L,QSA]
RewriteRule ^dash/ dash/index.php [NC,L,QSA]
RewriteRule ^something/ something/index.php [NC,L,QSA]
RewriteRule ^ index.php [NC,L,QSA]
also if you put htaccess in every directory you may use this in all directories.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [NC,L,QSA]

Trailing slash at end of URL wordpress

Dears,
I want to add / at the end of each url of site, below is what i found online, it works good, but in wp-admin it gives me wp-admin/index.php/index.php/. Like everytime i click on dashboard it will add /index.php/
code from htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1/ [L,R=301]
</IfModule>
Please advise.
Thanks
Keep redirect rule before your default WP rule:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !/$
RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI}/ [L,R=301,NE]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
Make sure to use a new browser for your testing.

Redirect to trailng slash (htaccess)

Trying to add a trailing slash to every link. For instance:
http://testsite.com/products
should 301 redirect to:
http://testsite.com/products/
etc. But how? Here is my current .htaccess:
AddDefaultCharset utf-8
Options -Indexes
RewriteEngine On
RewriteBase /
RewriteRule ^.htaccess$ - [F]
RewriteCond %{REQUEST_URI} !\.(ico|css|js|txt)$ [NC]
RewriteCond %{REQUEST_FILENAME} !^/admin
RewriteCond %{REQUEST_FILENAME} !^/migrate
RewriteCond %{REQUEST_FILENAME} !^/install
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*[^/])$ /$1/ [L,R=301]

unable to rewrite url - PHP

I have a link -
http://www.website.com/vendor.php/brand-name
Here brand name is dynamic and this works fine
But now I want to convert this link into
http://www.website.com/vendor/brand-name
when i try to access this - i get No input file specified.
I want to remove .php for only one file in my project - vendor.php
and want to run it as
http://www.website.com/vendor/brand-name
DirectoryIndex index.php
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule ^vendor/brand-name$ /vendor.php/$1 [L]
RewriteRule ^(.*)$ /vendor.php?tag=$1 [L]
Options -Indexes
RewriteEngine on
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward it to vendor.php
RewriteRule . vebdor.php
This should work
DirectoryIndex index.php
RewriteEngine on
RewriteBase /
#Rewrite "/vendor/foo" to "vendor.php/foo"
RewriteRule ^vendor/([^/]+)/?$ /vendor.php/$1 [NC,L]
#Rewrite to vendor.php?tag=
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /vendor.php?tag=$1 [L]

php htaccess folders management

For now i have all requests to my domain to go through /index.php
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ $1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . /index.php [L]
However i want to add an exception. If the request goes to folder "/this_specific_folder/" then it should go for "/this_specific_folder/index.php" instead of "/index.php", without breaking the current existing logic.
How can i achieve this?
You can have it this way:
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(this_specific_folder)(?:/.*)?$ /$1/index.php [L,NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ $1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . /index.php [L]

Categories