How to remove extensions from urls in the website - web-deployment

I try to remove extensions from the url by creating a .htaccess page in the root folderwith the following code
RewriteEngine
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php
but it is not working pls help me out......

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule .* $0.php
use this code in your .htaccess file
and remove the extensions of your php files in a href itself

Related

How do I pass control to another .htaccess file for all paths beneath a directory?

My site ww.example.com runs WordPress in its root directory, meaning that any paths are redirected to the WordPress install to be evaluated. I also have an install of DokuWiki under www.example.com/path/to/wiki/, which similarly uses .htaccess to deliver wiki pages at paths like www.example.com/path/to/wiki/wikipage.
The file structure on the server stores all the non-WordPress content in a subdirectory called content, so the Dokuwiki install is actually located in content/path/to/wiki/.
Unfortunately, whilst www.example.com/path/to/wiki/ displays correctly, www.example.com/path/to/wiki/wikipage is clearly passed back to the top-level WordPress .htaccess and returns a 404 error.
What do I need in my .htaccess files to make this set-up work?
Example .htaccess files
Top-level WordPress .htaccess
# Rewrite to content directory
RewriteCond %{DOCUMENT_ROOT}/content/$1 -f [OR]
RewriteCond %{DOCUMENT_ROOT}/content/$1index.php -f [OR]
RewriteCond %{DOCUMENT_ROOT}/content/$1index.html -f
RewriteRule ^(.*)$ /content/$1 [L]
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
DokuWiki .htaccess
RewriteEngine on
RewriteBase /path/to/wiki
RewriteRule ^_media/(.*) lib/exe/fetch.php?media=$1 [QSA,L]
RewriteRule ^_detail/(.*) lib/exe/detail.php?media=$1 [QSA,L]
RewriteRule ^_export/([^/]+)/(.*) doku.php?do=export_$1&id=$2 [QSA,L]
RewriteRule ^$ doku.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) doku.php?id=$1 [QSA,L]
I would think that all you need to do is omit the path to wiki and content directories from your .htaccess file in the root and include the path in the first rewriterule.
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{DOCUMENT_ROOT}/content/$1 -f [OR]
RewriteCond %{DOCUMENT_ROOT}/content/$1index.php -f [OR]
RewriteCond %{DOCUMENT_ROOT}/content/$1index.html -f
RewriteRule ^(path/to/wiki/.+/?)$ /content/$1 [L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_URI} !^/(path/to/wiki|content)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

.htaccesss RewriteCond %{REQUEST_FILENAME} !-d does not work

I want to install WordPress in subdirectory and remove index.php in permalinks.
The server is IIS 6.0, support rewrite.
My webserver has the following directories:
webroot
--wp [wordpress folder]
webroot/.htaccess
RewriteCond %{HTTP_HOST} ^(www\.)?a.luckyet\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/wp/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /wp/$1
RewriteCond %{HTTP_HOST} ^(www\.)?a.luckyet\.com$ [NC]
RewriteRule ^(/)?$ wp/
webroot/wp/.htaccess
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f #1
RewriteCond %{REQUEST_FILENAME} !-d #2
RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L] #3
It works when I visit a.luckyet.com and a.luckyet.com/hello-world.html
But it does not work when I visit a.luckyet.com/wp-login.php or a.luckyet.com/wp-admin
The #3 works fine, but #1 and #2 can not work properly. Then I saw here and change the content of webroot/wp/.htaccess to:
RewriteEngine on
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
It still does not take effect. Can anyone help me? Thanks in advance!
Update:
ISAPI_Rewrite version is 3.0.
All code in webroot/.htaccess:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?a.luckyet\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/wp/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /wp/$1
RewriteCond %{HTTP_HOST} ^(www\.)?a.luckyet\.com$ [NC]
RewriteRule ^(/)?$ wp/
All code in webroot/wp/.htaccess:
RewriteEngine on
# For file-based wordpress content (i.e. theme), admin, etc.
RewriteRule wp-(.*) wp-$1 [L]
# For normal wordpress content, via index.php
RewriteRule ^/$ index.php [L]
RewriteCond %{REQUEST_FILENAME} !-f #1
RewriteCond %{REQUEST_FILENAME} !-d #2
RewriteRule (.*) index.php/$1 [L]
Wordpress permalink is:
/%postname%.html
Thus, Wordpress can work fine when visit http://a.luckyet.com/ or http://a.luckyet.com/hello-world.html
Question:
If there is a real file like a.html in webroot/wp/, like webroot/wp/a.html, wordpress 404 error will be reported when visit http://a.luckyet.com/a.html, . How can I fixed this?
You're dynamically rewriting the URLs with the .htaccess file and WordPress settings to tack on the .html extension - any files that are "real-life" .html files are being handled upstream by the IIS Handler Mappings.
You'll have to update your Handler Mappings in IIS for .html files especially to direct the requests directly to the physical file.

Rewrite rule for everything except a folder

I have an application that uses Zend Framework but has a WordPress blog under the public directory (folder is named "blog").
Accessing the blog's homepage is fine, but when I try to access the posts, my htaccess rules have it go through Zend Framework. What do I need to modify in my /public/.htaccess file to have it ignore requests to the /public/blog directory?
Here's the current .htaccess file:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
Thanks!
I think, this should work
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/public/blog/
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

rewritecond exclude url in .htaccess

I have these working rewrite rules :
# Allow access to assets folder from plugins folders
RewriteRule ^app/plugins/(.+)/assets - [L]
# forbid access to files and folders under app
RewriteRule ^app/.*$ - [L,F]
# rewrite to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?action=$1 [L,QSA]
Now I would like to exclude from these rules everything located under http://www.mywebsite.com/wordpress/...
Therefore I've added a new rewrite condition :
...
# rewrite to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^\/wordpress\/ [NC]
RewriteRule ^(.*)$ index.php?action=$1 [L,QSA]
But it dosen't work. When I try to access something like this :
http://www.mywebsite.com/wordpress/contact-us/
it redirects me to index.php...
Any help would be really appreciated.
Ok I finally found what was going wrong with all of this :
In fact I did not notice that a .htaccess file was present in my /wordpress directory.
So on the .htaccess of my root directory I've added this rule on top of all the others :
RewriteRule ^wordpress - [L]
Then in the .htaccess of the wordpress directory I've these rules :
RewriteBase /wordpress/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wordpress/index.php [L]
I don't know if everything is optimized but it works !

css in codeigniter

Hi i have such a problem in codeigniter. I cant use styles of my .css file. But I know that this filt is connected to my views. (Firebug). Here is my link for connecting:
`<link rel="stylesheet" href="images/Enlighten.css" type="text/css" />`
css file in directory /images/Enlighten.css
Here is my htaccess file:
Options +FollowSymLinks
Options -Indexes
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|template|robots\.txt|public|)
RewriteCond %{REQUEST_URI} !\.(css¦js¦jpg¦gif)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L,QSA]
I think that my mistake is in this file.(I dont deal in this file :(( )
P.S Everywhere when i use styles from Enlighten.css text print as '??????????'
How about making it less complicated like this:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
ps.
It's best not to place your CSS in the images directory to prevent confusion.
I always use an assets folder and organize everything in there:
/Assets
/css
/images
/js
use following code for your htaccess file :-
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
I recommend to use the following .htaccess:
AddDefaultCharset UTF-8
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
#Removes access to the system folder by users.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#Prevents user access to the application folder
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>

Resources