How to rename only specific url through htaccess? - .htaccess

I have managed to remove the .php extension using the below htaccess code but the issue i face now is index.php shows like www.site.com/index
could someone help me out to rename it to www.site.com/home instead of /index?
Here is my complete htaccess file
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\?*$ pages.php?$1 [L,QSA]
RewriteCond %{THE_REQUEST} /([^.]+)\.php [NC]
RewriteRule ^ /%1 [NC,L,R]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [NC,L]
RewriteCond %{THE_REQUEST} /([^.]+)\.php [NC]
RewriteRule ^ /%1 [NC,L,R]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [NC,L]
<IfModule mod_deflate.c>
<FilesMatch "\.(css|x?html?|php)$">
SetOutputFilter DEFLATE
</FilesMatch>
</IfModule>
<IfModule mod_expires.c>
ExpiresByType text/css "access plus 1 month"
ExpiresByType text/javascript "access plus 1 month"
ExpiresByType text/html "access plus 1 month"
ExpiresByType application/javascript "access plus 1 month"
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType image/x-icon "access plus 1 month"
</IfModule>
<IfModule mod_rewrite.c>
RewriteCond %{QUERY_STRING} (\<|%3C).*script.*(\>|%3E) [NC,OR]
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
RewriteRule .* index.php [F,L]
</IfModule>
Really appreciate your kind help.

Could you please use following Rules set in your .htaccess file once. Please make sure to clear your browser cache before testing your URLs.
RewriteEngine On
RewriteBase /
##new redirection rules here for index.php to home.
RewriteRule ^index\.php/?$ /home? [R=301,NC,L]
RewriteRule ^home/?$ site/index.php [QSA,NC,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\?*$ pages.php?$1 [L,QSA]
RewriteCond %{THE_REQUEST} /([^.]+)\.php [NC]
RewriteRule ^ /%1 [NC,L,R]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [NC,L]
RewriteCond %{THE_REQUEST} /([^.]+)\.php [NC]
RewriteRule ^ /%1 [NC,L,R]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [NC,L]
<IfModule mod_deflate.c>
<FilesMatch "\.(css|x?html?|php)$">
SetOutputFilter DEFLATE
</FilesMatch>
</IfModule>
<IfModule mod_expires.c>
ExpiresByType text/css "access plus 1 month"
ExpiresByType text/javascript "access plus 1 month"
ExpiresByType text/html "access plus 1 month"
ExpiresByType application/javascript "access plus 1 month"
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType image/x-icon "access plus 1 month"
</IfModule>
<IfModule mod_rewrite.c>
RewriteCond %{QUERY_STRING} (\<|%3C).*script.*(\>|%3E) [NC,OR]
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [NC,OR]
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2}) [NC]
RewriteRule .* index.php [F,L]
</IfModule>

Related

Redirect not works correctly

This simple rule should redirect to url without one word (picture-display):
RewriteRule en/catalog/picture-display/(.*)$ en/catalog/$1 [L,NC,R=302]
But it redirect from www.example.com/en/catalog/picture-display/something to www.example.com/en. What I am doing bad?
Before this rule I have this. Would not influence it?
RewriteRule ^\.htaccess$ - [F]
RewriteCond %{REQUEST_URI} =""
RewriteRule ^.*$ /public/index.php [NC,L]
RewriteCond %{REQUEST_URI} !^/public/.*$
RewriteRule ^(.*)$ /public/$1
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^.*$ - [NC,L]
RewriteRule ^public/.*$ /public/index.php [NC,L]
EDIT
Whole .htaccess:
path/.htaccess
Header unset ETag
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/jpg "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/png "access plus 1 month"
ExpiresByType text/css "access plus 1 week"
ExpiresByType application/x-javascript "access plus 1 week"
ExpiresByType application/javascript "access plus 1 week"
</IfModule>
<IfModule mod_headers.c>
<FilesMatch "\.(ico)$">
Header set Cache-Control "max-age=29030400"
</FilesMatch>
</IfModule>
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteRule ^/?$ /public/index.php [L]
RewriteRule ^\.htaccess/?$ - [NC,F]
RewriteCond %{REQUEST_URI} =""
RewriteRule ^.*$ /public/index.php [NC,L]
RewriteCond %{REQUEST_URI} !^/public/.*$ [NC]
RewriteRule ^(.*)/?$ /public/$1
RewriteRule ^(cs/katalog)/obrazkove-zobrazeni/(.*)/?$ $1/$2 [L,NC,R=302]
RewriteRule ^(en/catalog)/picture-display/(.*)/?$ $1/$2 [L,NC,R=302]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^.*$ - [NC,L]
RewriteRule ^public/.*$ /public/index.php [QSA,NC,L]
htaccess to route from documentRoute:
path/public/.htaccess (document route) - there is index.php
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ /index.php [NC,L]
Result of cmd
Please try add rule:
RewriteRule ^en/catalog/picture-display/(.*)$ en/catalog/$1 [L,NC,R=302]
before line with RewriteRule ^/?$ /public/index.php [L]
Please try following htaccess rules in your file. Please make sure to clear your browser cache before testing your URLs.
Header unset ETag
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/jpg "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/png "access plus 1 month"
ExpiresByType text/css "access plus 1 week"
ExpiresByType application/x-javascript "access plus 1 week"
ExpiresByType application/javascript "access plus 1 week"
</IfModule>
<IfModule mod_headers.c>
<FilesMatch "\.(ico)$">
Header set Cache-Control "max-age=29030400"
</FilesMatch>
</IfModule>
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [F,L]
RewriteCond %{REQUEST_URI} !^/public [NC]
RewriteRule ^(.*)/?$ /public/$1 [L]
RewriteRule ^/?$ /public/index.php [L]
RewriteRule ^public /public/index.php [QSA,NC,L]
RewriteRule ^\.htaccess/?$ - [NC,F]
RewriteRule ^(en/catalog)/picture-display/(.*)/?$ $1/$2 [L,NC,R=302]
RewriteRule ^(cs/katalog)/obrazkove-zobrazeni/(.*)/?$ $1/$2 [L,NC,R=302]
Keep your path/public/.htaccess (document route) like as follows:
RewriteOptions Inherit
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ /index.php [NC,L]
Have it this way in your site root .htacccess:
RewriteEngine On
RewriteRule ^\.htaccess/?$ - [NC,F]
# add www and turn on https in same rule
RewriteCond %{HTTP_HOST} !^www\. [NC,OR]
RewriteCond %{HTTPS} !on
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://www.%1%{REQUEST_URI} [R=302,L,NE]
RewriteRule ^(cs/katalog)/obrazkove-zobrazeni/(.*)/?$ /$1/$2 [L,NC,R=302]
RewriteRule ^(en/catalog)/picture-display/(.*)/?$ /$1/$2 [L,NC,R=302]
RewriteRule ^/?$ /public/index.php [L]
RewriteCond %{REQUEST_URI} !^/public/ [NC]
RewriteRule .* public/$0 [L]
Correct htaccess which do what I wanted is:
RewriteEngine On
RewriteRule ^cs/katalog/obrazkove-zobrazeni/(.*)/?$ /cs/katalog/$1 [L,NC,R=302]
RewriteRule ^en/catalog/picture-display/(.*)/?$ /en/catalog/$1 [L,NC,R=302]
RewriteRule ^\.htaccess/?$ - [NC,F]
RewriteCond %{REQUEST_URI} =""
RewriteRule ^.*$ /public/index.php [NC,L]
RewriteCond %{REQUEST_URI} !^/public/.*$ [NC]
RewriteRule ^(.*)/?$ /public/$1
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^.*$ - [NC,L]
RewriteRule ^public/.*$ /public/index.php [QSA,NC,L]
I would like to thank to #RavinderSingh13 and others which tried out help me, but their solutions didn't work unlike mine.

how to rewrite for a page to base url with id in php using Htaccess

pls, help me to resolve this issues, we are facing this problem from last couple of days.
I have a problem with my .htaccess
I have set my $base_url = http://localhost/example.com/ Like this
I have a URL that looks like:
http://localhost/example.com/test.php?id=10
I want to convert this url like this :
http://localhost/example.com/10
Here is my .Htaccess code
RewriteEngine On
<ifModule mod_headers.c>
Header set Connection keep-alive
</ifModule>
## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType text/html "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 1 month"
</IfModule>
## EXPIRES CACHING ##
#AddOutputFilterByType DEFLATE text/plain
#AddOutputFilterByType DEFLATE text/html
#AddOutputFilterByType DEFLATE text/xml
#AddOutputFilterByType DEFLATE text/css
#AddOutputFilterByType DEFLATE application/xml
#AddOutputFilterByType DEFLATE application/xhtml+xml
#AddOutputFilterByType DEFLATE application/rss+xml
#AddOutputFilterByType DEFLATE application/javascript
#AddOutputFilterByType DEFLATE application/x-javascript
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^([^\.]+)$ $1.html [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)/?$ $0.php [NC,L]
RewriteRule ^user/profile/([A-Za-z0-9-\s&/()+']+) user-profile-edit.php?name=$1 [NC,B,L]
RewriteRule ^user/profile user-profile.php [NC,B,L]
RewriteRule ^user/dashboard user-dashboard.php [NC,B,L]
RewriteRule ^user/address user-addresses.php [NC,B,L]
RewriteRule ^user/add-address user-address-add.php [NC,B,L]
RewriteRule ^user/booking user-booking.php [NC,B,L]
# Condition For Test Page
RewriteCond %{QUERY_STRING} (^|&)id=\$1($|&)
RewriteRule ^tests\.php$ /$1?&%[R=301,L]
So How to fix this problem?
Inside example.com/.htaccess you may try these rules:
RewriteEngine On
RewriteCond %{THE_REQUEST} \s/+([^/]+)/test\.php\?id=([\w-]+)\sHTTP [NC]
RewriteRule ^ /%1/%2? [R=302,L,NE]
RewriteRule ^user/profile/([-\w\s&/()+']+)/?$ user-profile-edit.php?name=$1 [NC,QSA,L]
RewriteRule ^user/profile/?$ user-profile.php [NC,L]
RewriteRule ^user/dashboard/?$ user-dashboard.php [NC,L]
RewriteRule ^user/address/?$ user-addresses.php [NC,L]
RewriteRule ^user/add-address user-address-add.php [NC,L]
RewriteRule ^user/booking/?$ user-booking.php [NC,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.+?)/?$ $1.html [L]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]
RewriteRule ^([\w-]+)/?$ test.php?id=$1 [QSA,L]

htaccess domain access without file endings

I want domain.de/test.php to appear without the .php.
I tried this, but its not working. Is there a conflict maybe?
This is my full .htaccess now. Do I have an error somewhere or conflict?
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . / [L,R=301]
# FORCE HTTPS
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://bm-translations.de/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
#remove the need for .php extention
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
<IfModule mod_filter.c>
<IfModule mod_deflate.c>
## Enable gzip compression ##
# compress text, HTML, JavaScript, CSS, and XML
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
# Remove browser bugs
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
Header append Vary User-Agent
## END Enable gzip compression ##
</IfModule>
</IfModule>
AddType font/woff .woff
ExpiresByType font/woff "access plus 1 year"
AddOutputFilterByType DEFLATE font/woff
AddType image/svg+xml .svg
AddOutputFilterByType DEFLATE image/svg+xml
## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 3 month"
ExpiresByType image/jpg "access 3 month"
ExpiresByType image/jpeg "access 3 month"
ExpiresByType image/gif "access 3 month"
ExpiresByType image/png "access 3 month"
ExpiresByType image/svg+xml "access 3 month"
ExpiresByType text/css "access 3 month"
ExpiresByType text/html "access 3 month"
ExpiresByType application/pdf "access 3 month"
ExpiresByType text/x-javascript "access 3 month"
ExpiresByType application/javascript "access plus 3 month"
ExpiresByType application/x-shockwave-flash "access 3 month"
ExpiresByType image/x-icon "access 3 year"
ExpiresDefault "access 3 month"
</IfModule>
## EXPIRES CACHING ##
I tried to put the part with file-extension on top and at the bottom, but everywhere its not working.
You may use these rules in site root .htaccess:
RewriteEngine On
# remove www and redirect http to https
RewriteCond %{HTTP_HOST} ^www\. [NC,OR]
RewriteCond %{HTTPS} !on
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [R=301,L,NE]
# To externally redirect /dir/file.php to /dir/file
RewriteCond %{THE_REQUEST} \s/+(.+?)\.php[\s?] [NC]
RewriteRule ^ /%1 [R=301,NE,L]
# internally add .php extension
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]
Solution was to add RewriteBase /
RewriteEngine on
RewriteBase /
# FORCE HTTPS
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://bm-translations.de/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
#remove the need for .php extention
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . / [L,R=301]

http to https redirect htaccess

I was trying to edit my htaccess file to redirect from http to https.
This one works for all pages except the homepage for every language:
http://cinqueterre.a-turist.com/deu
redirects to
https://cinqueterre.a-turist.com/https://cinqueterre.a-turist.com/deu
It's a little complicated script
Here is it:
Update: I improved a little the script, now it's not such complicated, and doesn't work if I add https redirect
DirectoryIndex 1.php index.html$ index.php
ErrorDocument 404 /404.php
RewriteEngine on
Options -Multiviews
RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
RewriteCond %{HTTPS_HOST} ^www\.cinqueterre\.a\-turist\.com$ [NC]
RewriteRule (.*) https://cinqueterre.a-turist.com/$1 [R=301,L]
RewriteCond %{HTTPS_HOST} ^cinqueterre.a-turist\.com$ [OR]
RewriteCond %{HTTPS_HOST} ^www\.cinqueterre.a-turist\.com$
RewriteRule ^(rus|ita|fra|deu|ukr|pol|esp)\/index\.php$ https\:\/\/cinqueterre.a-turist\.com\/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+)$ $1.php [L,QSA]
#if its not a directory
RewriteCond %{REQUEST_FILENAME} !-d
#and it has a trailing slash then redirect to URL without slash
RewriteRule ^(.+)/$ /$1 [L,R=301]
Options All -Indexes
## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 2 days"
</IfModule>
## EXPIRES CACHING ##
<ifmodule mod_deflate.c>
AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript
</ifmodule>
Try getting rid of all of your redirects, they're in the wrong place.
You need to add redirects before this rule:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+)$ $1.php [L,QSA]
And you want something like this:
RewriteCond %{THE_REQUEST} \ /+.*index\.php
RewriteRule ^(rus/|ita/|fra/|deu/|ukr/|pol/|)index\.php$ https://cinqueterre.a-turist.com/$1 [R=301,L]
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^(www\.)?cinqueterre.a-turist\.com$ [NC]
RewriteRule ^(.*)$ https://cinqueterre.a-turist.com/$1 [R=301,L]

301 redirection in .htaccess file not working

I'm attempting to redirect an internal link via .htaccess file and it's not working. Below is my .htaccess file '# Redirects'.
How might I better structure the code to allow working redirection links?
# Use PHP 5.3
AddType application/x-httpd-php53 .php
# Redirect www to non-www
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# Redirects
Redirect 301 /oldpage http://domain/newpage
# Start Hotlink Protection
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?domain.com [NC]
RewriteRule \.(jpg|jpeg|png|gif)$ - [NC,F,L]
# EXPIRES CACHING
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType text/js "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 2 days"
</IfModule>
Your redirect statement is part of mod_alias, but all the rest of the rewrite rules you have belong to mod_rewrite. Those two modules processes the request at different points of the processing pipeline, so if you use them concurrently, sometimes they'll not play nicely with each other. You should just use mod_rewrite in this case as well as putting the redirect rule BEFORE your wordpress routing rules. This is because wordpress will route what you actually want to redirect.
So:
# Use PHP 5.3
AddType application/x-httpd-php53 .php
# Redirect www to non-www
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
#### INSERT THE REDIRECTS HERE
# Redirects
RewriteRule ^oldpage(.*)$ http://domain/newpage$1 [L,R=301]
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
### Remove the redirect from here
# Start Hotlink Protection
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?domain.com [NC]
RewriteRule \.(jpg|jpeg|png|gif)$ - [NC,F,L]
And then the rest of your htaccess file

Resources