Rewriting only for HTML page requests - .htaccess

I have the following in my htaccess files:
Options +FollowSymLink
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-F
RewriteCond %{REQUEST_FILENAME} !-D
RewriteRule (.*) index.php [L]
I am guessing the above is the reason why my images are not appearing as I am redirecting everything to index.php?
How can I just limit this to HTML files and PHP files?
Thanks all for any help

Options +FollowSymLinks
RewriteEngine on
RewriteRule \.html$ /index.php [R=301,L]

Related

htaccess delete and ban all extensions and add / to the end of the URL

I am making a small cms in php. Through htaccess I would like to delete and block all extensions (.php .html. Htm etc.) and add a / at the end of the url.
ex. www.miosito/ article-name/
Options -Indexes
DirectoryIndex home.php
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ core.php
this is my current htaccess.
Sorry for my bad English and thank you very much in advance
With your shown samples/attempts, could you please try following htaccess Rules file. Please make sure to clear browser cache before testing your URLs.
RewriteEngine ON
##Excluding Indexes and MultiViews options here.
Options -Indexes -MultiViews
##Rule for url http://localhost:80/test here.
RewriteRule ^(test)/?$ $1/category [R=301,L]
RewriteRule ^(test/category)/?$ $1.php [NC,L]
##Rule for forbidding html OR htm OR php extension files.
RewriteRule \.(html|php|Htm)/?$ - [F,NC,L]
##Rule for adding / at end of urls.
RewriteCond %{REQUEST_URI} /+[^\.]+$
RewriteRule ^(.+[^/])$ %{REQUEST_URI}/ [R=301,L]
##Rules for non-existing pages to be served here.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ core.php [QSA,L]
Try out this code in site root .htaccess after completely clearing your browser cache:
Options -Indexes
DirectoryIndex home.php
RewriteEngine On
# block direct access to .php, .html, .html extensions files
RewriteCond %{THE_REQUEST} \.(html?|php)[?\s/] [NC]
RewriteRule . - [F]
## Adding a trailing slash
RewriteCond %{ENV:REDIRECT_STATUS ^$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule [^/]$ %{REQUEST_URI}/ [L,NE,R=301]
# core handler
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . core.php [L]

Point directoryIndex to multiple strings

I have home.php as a directory index file.
This can be accessed like: http://localhost/joacmedia/home.php
How do I make the server point to the same home.php if user type http://localhost/joacmedia/index.php
.htaccess file looks like this:
Options -Indexes
DirectoryIndex home.php
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ home.php?url=$1 [L,QSA]
Just rewrite the index.php to home.php
RewriteRule ^index.php$ home.php [L]
Your htaccess should look like the following with these settings
Options -Indexes
DirectoryIndex home.php
RewriteEngine On
RewriteRule ^index.php$ home.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ home.php?url=$1 [L,QSA]
Keep your htaccess file besides joacmedia folder and try following rules.
Please make sure to clear browser cache before testing your URLs.
RewriteEngine ON
RewriteRule ^joacmedia/index\.php home.php [QSA,NC,L]

htacces doesn't rewrite url correctly

I made Ajax navigation that call pages from a /pages file in a div, and I've tried many things to remove the .php from my URLs but I can't find the solution.
Here is my .htaccess file:
Options +MultiViews +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9\-]+)\.php$ index.php?p=$1 [L]
RewriteRule ^pages/([a-z0-9\-]+)$ index.php?slug=$1
So everything works well but I can't change my URL: www.mywebsite.com/about.php to www.mywebsite.com/about
Try using this:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
It should remove .php extension from the end of your URLs.

Rewriting subfolders using nice url

When I go to http://www.example.com/youtube/detail/abvcde in my browser, I want to internally rewrite the url to http://www.example.com/youtube/detail.php?id=abvcde. I tried to do this with the following .htaccess, but it gives a 404 error.
Currently my .htaccess looks like this:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) $1.php [L]
Put the following code in a htaccess file in server root directory:
RewriteEngine On
RewriteRule ^youtube/detail/(.+)$ youtube/detail.php?id=$1 [L]
You can put this code in your /youtube/.htaccess
Options -MultiViews
RewriteEngine On
RewriteBase /youtube/
RewriteRule ^detail/([^/]+)$ detail.php?id=$1 [L]

.htaccess rewrite except images and script files

I have the following rewrite:
RewriteRule ^/blog/(.*)$ http://www.domain.co.uk [NC,L,R=301]
But I only want it to happen if it is not a image file (.jpg, .gif, .png) or a script file (.js). Does anyone know how to set this?
(It is a wordpress blog and I want to redirect all pages but keep the scripts and images active.)
Thanks
RewriteCond %{REQUEST_FILENAME} !^(.+)\.js$
RewriteCond %{REQUEST_FILENAME} !^(.+)\.png$
RewriteCond %{REQUEST_FILENAME} !^(.+)\.jpg$
RewriteCond %{REQUEST_FILENAME} !^(.+)\.jpeg$
RewriteCond %{REQUEST_FILENAME} !^(.+)\.gif$
RewriteRule ^/blog/(.+)$ http://www.domain.co.uk [NC,L,R=301]
I found that I had to edit the .htaccess file located in the wordpress file to this:
RewriteEngine On
RedirectMatch 301 ^/blog/$ http://www.domain.co.uk
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . / [R=301,L]
</IfModule>
# END WordPress

Resources