Ignore a particular folder in htaccess - php

I am facing issues regarding my .htaccess. The .htaccess works, but it causes a problem with the admin folder. Would it be possible to exclude that specific folder from this .htaccess? Here is my .htaccess. It is outside the admin folder.
Options -MultiViews
ErrorDocument 404 http://localhost/blo-prt/err.php
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [L,QSA]
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^blo/([^/\.]+)?$ blo-det.php?postlist=$1 [L,QSA]
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^category/blo/([^/\.]+)?$ blo-prior.php?bloglist=$1 [L,QSA]
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^tep/([^/\.]+)?$ temp-det.php?telist=$1 [L,QSA]
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^category/tep/([^/\.]+)?$ temp-of-prior.php?tlist=$1 [L,QSA]

You should add this to your RewriteConds:
# if request is not for the /admin/
RewriteCond %{REQUEST_URI} !^/admin/ [NC]
Personally, I use this code to remove the .php extension:
# enable url rewriting
RewriteEngine On
# remove .php
RewriteCond %{THE_REQUEST} /([^.]+)\.php [NC]
RewriteRule ^ /%1 [NC,L,R]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [NC,L]
Also, you should only type RewriteEngineOn just once at the top of the file.

Related

how to remove question mark from two php URLs in .htaccess

I want to remove question mark from two URLs like this:
URL 1
http://localhost:8888/events/event.php?id=222
to
http://localhost:8888/events/event/222
URL 2
http://localhost:8888/membership/register.php?id=162
to
http://localhost:8888/membership/register/162
i'm use this code in .htaccess and just the 'event' page work:
Options -MultiViews
RewriteEngine On
RewriteBase /
# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} /events/event(?:\.php)?\?id=([^\s&]+) [NC]
RewriteRule ^ /events/event/%1? [R=302,L,NE]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^events/event/([^.]+?)/?$ events/event.php?id=$1 [QSA,L,NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^.]+?)/?$ $1.php [L]
# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} /membership/register(?:\.php)?\?id=([^\s&]+) [NC]
RewriteRule ^ /membership/register/%1? [R=302,L,NE]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^membership/register/([^.]+?)/?$ membership/register.php?id=$1 [QSA,L,NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^.]+?)/?$ $1.php [L]
You can use:
Options -MultiViews
RewriteEngine On
RewriteBase /
# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} /events/event(?:\.php)?\?id=([^\s&]+) [NC]
RewriteRule ^ /events/event/%1? [R=302,L,NE]
RewriteCond %{THE_REQUEST} /membership/register(?:\.php)?\?id=([^\s&]+) [NC]
RewriteRule ^ /membership/register/%1? [R=302,L,NE]
# skip all files and directories from rewrite rules below
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
# rewrite from pretty URL
RewriteRule ^events/event/([^.]+?)/?$ events/event.php?id=$1 [QSA,L,NC]
RewriteRule ^membership/register/([^.]+?)/?$ membership/register.php?id=$1 [QSA,L,NC]
# Rewrite with .php
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^.]+?)/?$ $1.php [L]

user friendly url without filename in core php site

I have a link www.example.com/folder/filename.php?cid=1&title=Chekcing
I want to make user friendly url from above link to : www.example.com/folder/1/Checking/
I have an .htaccess code :
**
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^GET\s([^.]+)\.php\s [NC]
RewriteRule ^ %1 [R,L]
RewriteCond %{THE_REQUEST} ^GET\s([^.]+)\.php\?cid=([^&\s]+)\&title=([^&\s]+) [NC]
RewriteRule ^ %1/%2/%3? [R,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.+?)/([^/]+)/?$ $1.php?cid=$2&title=$3[QSA,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^(.*?)/?$ $1.php [L]
**
But it only returns filename without .php : **www.example.com/folder/filename/1/Checking**
I want to remove filename too, from the url...
Thanks in Advance...
Try this :
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteEngine On
RewriteBase /foldername/
#Remove .php extensions from php files :
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [NC,L]
#__________
#Redirect urls with query strings to cleaner version :
RewriteCond %{THE_REQUEST} /filename\.php\?cid=([^&]+)&title=([^\s]+) [NC]
RewriteRule ^ %1/%2? [NC,R,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/?$ foldername/filename.php?cid=$1&title=$2 [QSA,L,NC]
#___________

.htaccess for multiple rewrite rules

I wanted to create an htaccess file to remove the .php extension and change course.php?id=1 to course/1. But that does not seem to work out. Can any one correct my htaccess?(I am quite new to writing htaccess files)
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/$ $1.php
RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]
# If request is for a file that does actually exist, don't rewrite.
RewriteCond %{REQUEST_FILENAME} !-f
# If request is for a directory that does actually exist, don't rewrite.
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/course/(.*)$ /course.php?id=$1 [NC]
Options -Indexes
Keep it this way:
Options -Indexes
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
# add a trailing slash
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule ^(.+)$ $1/ [R=301,L]
RewriteRule ^course/([^/]+)/?$ course.php?id=$1 [NC,L,QSA]
RewriteRule ^([^/]+)/$ $1.php [L]
RewriteRule ^([^/]+)/([^/]+)/$ $1/$2.php [L]

hide file extension in urls

For some reason this is not working for me. I added -Multiviews option because domain is from godaddy, but it's still not working.
htaccess
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
Place this code in your root .htaccess:
RewriteEngine On
RewriteCond %{THE_REQUEST} \s/+(?:index)?(.*?)\.php[\s?] [NC]
RewriteRule ^ /%1/ [R=301,L,NE]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC]
RewriteRule ^(.+?)/?$ /$1.php [L]

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