php htaccess folders management - php

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]

Related

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.

Username with folder mod_rewrite

I have this problem, I have this url example.com/directory/fotos/index.php?u=username and what I need to do is change it to
example.com/username/fotos
I already have a rule in htacces which changes the directory to username in case a username is found in index.php
RewriteEngine On
#RewriteBase /
RewriteCond %{REQUEST_URI} ^(.*)//(.*)$
RewriteRule . %1/%2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ directory/index.php?u=$0&%{QUERY_STRING} [L]
Which ouputs example.com/someusername
How can I do a new rule for the above case without conflicting with the current rule?
This should do:
RewriteEngine On
#RewriteBase /
RewriteCond %{REQUEST_URI} ^(.*)//(.*)$
RewriteRule . %1/%2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/([^/]+)/fotos/?
RewriteRule ^([^/]+)/?$ /directory/index.php?u=$1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/directory/fotos/?
RewriteRule ^([^/]+)/fotos/?$ /directory/fotos/index.php?u=$1 [L,QSA]

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]

Creating .htaccess hidden redirect

How can I make redirect from /katalog/protein/api and /katalog/protein/activelab to katalog/protein/?ms|manufacturer=API and katalog/protein/?ms|manufacturer=ActiveLab.
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/katalog/(protein|gainer)/(api|activelab)/?$ /katalog/$1/?ms|manufacturer=$2 [L,QSA]
Your code look fine, just remove the leading slash from RewriteRule's pattern.
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^katalog/(protein|gainer)/(api|activelab)/?$ /katalog/$1/?ms|manufacturer=$2 [L,QSA,NE,NC]

Php apache mod rewrite remove .php not working

I'm trying to remove .php from my url,
below is my .htaccess contents
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteBase /folder/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/?$ path.php?username=$1 [L,QSA]
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ $1.php [L]
</IfModule>
I don't have any idea what's going wrong.
Try this:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
You need an additional rule to redirect .php URL to non-php one. Try this code:
Options -MultiViews
RewriteEngine On
RewriteBase /folder/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/?$ path.php?username=$1 [L,QSA]
RewriteCond %{THE_REQUEST} \s/+folder/(.+?)\.php[\s?] [NC]
RewriteRule ^ %1? [R,L,NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]

Categories