Removing file extensions in .htaccess with wordpress - php

I have a static website running in conjunction with wordpress in the same dir, it all works fine. However, on the static pages that don't use wordpress I cannot seem to remove the .php file extensions my .htaccess file looks like this:
# BEGIN WordPress
<IfModule mod_rewrite.c>
ErrorDocument 404 /index2.php
RewriteEngine On
RewriteBase /index.php/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
#Alternate default index page
DirectoryIndex index2.php
ErrorDocument 404 http://example.com/index2.php
I have tried adding this code as you usually would but it wont work:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

Try this
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [L]

Related

Is my htaccess correct?

I'm trying to build a shopping cart using PHP & MySQL. Right now I'm in the process of creating product-detail pages. So this is how I set up my htaccess (located in the root folder):
Options +FollowSymLinks
Options -Indexes
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|images|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^\.]+)$ $1.php [NC,L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
My problem is I can only access a certain page if index.php is included. For example, http://localhost/thegamingplace/products/details/1 displays a "Not Found" error, but http://localhost/thegamingplace/index.php/products/details/1 works.
Can someone take a look at my htaccess and tell me what I'm doing wrong?
Try this:
RewriteCond %{REQUEST_URI} !^(index\.php|resources|images|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^\.]+)$ index.php/$1 [NC,L]
It works when tested at http://htaccess.mwl.be/
If it doesn't work make sure you have mod_rewrite installed and enabled.

404 error not work for /%post_id%/%postname%.html

i use /%post_id%/%postname%.html in my wordpress permalink.
404 eror dont work for this permalink if post or page not exist.
but for another link 404 work good.
this is my htaccess file :
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
thanks for your help.
Check this might be help you
set apache to "AllowOverride All"
mod_rewrite is present, .htaccess looks like this:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wikiarr_prd/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wikiarr_prd/index.php [L]
</IfModule>
# END WordPress
Permalinks structure:
/%postname%_%post_id%.html

Disable php execution directly with .htaccess

I have this on my htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [L]
</IfModule>
And in the index.php I get the REQUEST_URI so I can know what page to display.
But I have another files .php, how to make that all php execution like http://domain.com/file.php directs to index.php?
If I the line "RewriteCond %{REQUEST_FILENAME} !-f" then the sitemap.xml is not working.
Sorry for my bad english, and thanks for your help!
You can have it like this:
<IfModule mod_rewrite.c>
RewriteEngine On
# route all *.php to /index.php
RewriteCond %{THE_REQUEST} \s/+(.+?)\.php[/\s?] [NC]
RewriteRule !^index\.php$ index.php [L,NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [L]
</IfModule>

How to set index.php as default page?

I think after I put the code to remove the .php from URL, the index.php is not working anymore. Here is my .htaccess.
DirectoryIndex index.php
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
So, when I try to access some URL like: example.com/x/ does not work, but example.com/x/index/ works.
I don't know if this will help you, but try to use this as reference to your configuration. This has been taken from server that hosts my wordpress page (.htaccess file).
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Try this:
DirectoryIndex index.php
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^([^\.]+)$ $1/index.php [NC,L]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^\.]+)/$ $1.php [NC,L]

VHost & htaccess - 500 Internal Server error

I use ISPConfig 3 to manage my domains/subdomains.
I added subdomain parim.kristian.ee which would redirect to web/parim/ (note: web/ is my document root).
ISPConfig generated such redirect to apache config:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^parim.kristian.ee [NC]
RewriteRule ^/(.*)$ /parim/$1 [L]
Now if i'll try to get static resources, such as http://parim.kristian.ee/images/1x1.gif, it serves fine, but when redirect is to codeigniter, it doesn't work.
Htaccess in web/parim/ looks like this:
<IfModule mod_rewrite.c>
RewriteEngine on
Options -Indexes
#Handle CodeIgniter request
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 ./index.php
</IfModule>
NOTE: accessing the same folder via http://kristian.ee/parim/ works!
I s*ck at htaccess, so any help is appreciated.
# To remove index.php from URL
RewriteEngine On
RewriteBase /parim
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
Or Simple remove RewriteBase /parim

Categories