I am building a wiki using dokuwiki, and am using the nice URL feature which uses url rewriting through Apache on the webserver, to get rid of the ugly php urls. My problem is that I seem to be only getting 404 Not Found errors when searching for the pages using the new URLs.
This is the .htaccess file provided, and the RewriteBase is pointed to the correct location.
#Options -Indexes -MultiViews +FollowSymLinks
## make sure nobody gets the htaccess, README, COPYING or VERSION files
<Files ~ "^([\._]ht|README$|VERSION$|COPYING$)">
Order allow,deny
Deny from all
</Files>
## Uncomment these rules if you want to have nice URLs using
## $conf['userewrite'] = 1 - not needed for rewrite mode 2
RewriteEngine on
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]
RewriteRule ^index.php$ doku.php
## Not all installations will require the following line. If you do,
## change "/dokuwiki" to the path to your dokuwiki directory relative
## to your document root.
RewriteBase /dokuwiki
## If you enable DokuWikis XML-RPC interface, you should consider to
## restrict access to it over HTTPS only! Uncomment the following two
## rules if your server setup allows HTTPS.
#RewriteCond %{HTTPS} !=on
#RewriteRule ^lib/exe/xmlrpc.php$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R=301]
Make sure your Apache actually loads .htaccess files. You will probably need this in your Apache config:
AllowOverride All
Related
I installed Codeigniter 4.0.0.rc3 on my local computer using Wampserver and created a 'people' controller. I can access the page using this address:
http://127.0.0.1/election/index.php/people
But not without 'index.php':
http://127.0.0.1/election/people
And this is the error:
The requested URL /Projects/Web/election/public/index.php/people was not found on this server.
.htaccess is in the public directory and is working because the error shows index.php in the path.
This is my htaccess:
# Disable directory browsing
Options All -Indexes
# ----------------------------------------------------------------------
# Rewrite engine
# ----------------------------------------------------------------------
# Turning on the rewrite engine is necessary for the following rules and features.
# FollowSymLinks must be enabled for this to work.
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
# If you installed CodeIgniter in a subfolder, you will need to
# change the following line to match the subfolder you need.
# http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritebase
# RewriteBase /
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Rewrite "www.example.com -> example.com"
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,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 the front controller, index.php
RewriteCond $1 !^(index\.php|assets|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
# Ensure Authorization header is passed along
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
ErrorDocument 404 index.php
</IfModule>
# Disable server signature start
ServerSignature Off
# Disable server signature end
UPDATE: This htacces is working perfectly on a Linux Host but not working with Wampserver on Windows 10
In linux apache2 the following works, should be applicable to wampp's apache as well:
Make sure mode_rewrite is enabled
Edit your public .htaccess file as follows:
RewriteRule ^(.*)$ index.php/$1 [L]
to
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
(would appreciate if someone explains the QSA statement)
In app/Config/App.php edit:
public $indexPage = 'index.php';
to
public $indexPage = '';
I had to play around a lot before I figured it out, but I had installed CodeIgniter in a subfolder. (I access the website via http://127.0.0.1/myapp/).
I had configured the $baseURL parameter in the config file, but I kept getting that apache error. Just like you, if I added the /index.php in the URL, all my routes were working fine.
In /public/.htaccess, The QSA option didn't help, but this section just above did:
# If you installed CodeIgniter in a subfolder, you will need to
# change the following line to match the subfolder you need.
# http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritebase
RewriteBase /myapp/
Adding this allow mod_rewrite to work fine. Obviously you need to change /myappp/ to what your virtual subfolder is, in order for it to match the subfolder portion of the $baseURL parameter in Config/App.php
Hope this help !
I've set up a Wordpress site.
I need to recursively remove the .php extension on files in a specific folder.
Say:
www.domain.com/wordpresspage/ (set up with permalinks, all good).
I then need to remove .php recursively for folder:
domain.com/gz/*
The content of domain.com/gz/ should have the .php extension removed. But only for this folder.
Folder structure
/
-/images (No .htaccess rules should apply, Wordpress takes care of it.)
-/downloads (No .htaccess rules should apply, Wordpress takes care of it.)
-/gz (.htaccess change, to remove .php file extension, overwriting Wordpress, in this particular folder)
-file1 (No .htaccess rules should apply, Wordpress takes care of it.)
-file2 (No .htaccess rules should apply, Wordpress takes care of it.)
Before I used the following .htaccess content to remove .php extensions, but now I need to only force this on one folder, since Wordpress is taking care of the rest.
#RewriteBase /
#RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^.]+)\.php\ HTTP
#RewriteRule ^([^.]+)\.php$ https://example.com/$1 [R=301,L]
#RewriteCond %{REQUEST_URI} !(\.[^./]+)$
#RewriteCond %{REQUEST_fileNAME} !-d
#RewriteCond %{REQUEST_fileNAME} !-f
#RewriteRule (.*) $1.php [L]
I've tried a ton of things already, but the last few included:
Use the old .htaccess file that removes .php on all pages. This solves my path issue, but gives internal server error on the rest of the site.
Tried a gazillion ways of filtering out that folder recursively, to the point I'm no longer sure if it's even possible. (Don't even remember a fraction of what I tried).
Tried in the permalinks to add .php - but since it will redirect to remove it again, I'll get yet another Internal Server Error.
TL;DR - Can I recursively remove .php on a specific path in my .htaccess file, so Wordpress ignores this folder and let's it deal with it's own business?
Added after first round of help, my .htaccess file now looks like this:
# -FrontPage-
IndexIgnore .htaccess */.??* *~ *# */HEADER* */README* */_vti*
RewriteEngine On
# Only apply if request starts with /gz/
# followed by at least one character and ends with .php
RewriteCond %{REQUEST_URI} ^/?gz/[^.]+\.php$
# Redirect to the same location but without .php ant the end
RewriteRule ^/?(.*)\.php$ /$1 [R=301,L]
# Only apply if request starts with /gz/ followed by at least one character
RewriteCond %{REQUEST_URI} ^/?gz/[^.]+$
# and the request it not a real directory
RewriteCond %{REQUEST_FILENAME} !-d
# and the request it not a real file
RewriteCond %{REQUEST_FILENAME} !-f
# Rewrite the request with .php at the end
RewriteRule ^(.*)$ /$1.php [L]
<Limit GET POST>
order deny,allow
deny from all
allow from all
</Limit>
<Limit PUT DELETE>
order deny,allow
deny from all
</Limit>
AddType application/x-httpd-php-old .php
<IfModule security_module>
SecFilterEngine Off
</IfModule>
<IfModule security2_module>
SecRuleRemoveByID 1-99999
SecRuleRemoveByTag unoeuro
</IfModule>
After re-applying Permalinks, Wordpress adds this section to the .htaccess file:
# 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
Thanks in advance,
L
What you could do is the following
RewriteEngine On
# Only apply if no rewrite
RewriteCond %{ENV:REDIRECT_STATUS} ^$
# Only apply if request starts with /gz/
# followed by at least one character and ends with .php
RewriteCond %{REQUEST_URI} ^/?gz/[^.]+\.php$
# Redirect to the same location but without .php ant the end
RewriteRule ^/?(.*)\.php$ /$1 [R=301,L]
# Only apply if request starts with /gz/ followed by at least one character
RewriteCond %{REQUEST_URI} ^/?gz/[^.]+$
# and the request it not a real directory
RewriteCond %{REQUEST_FILENAME} !-d
# and the request it not a real file
RewriteCond %{REQUEST_FILENAME} !-f
# Rewrite the request with .php at the end
RewriteRule ^(.*)$ /$1.php [L]
So if you request e.g. /gz/gz5.php is will be redirect you to to /gz/gz5
and if the request is /gz/gz5 it will rewite to /gz/gz5.php
In the past, I have got this working no problems at all, but for some reason on my new server I just can't get it to work.
I have the following .htaccess file in the root of my application
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
I have also enabled mod_rewrite and have confirmed this with php_info()
my site is located at /var/www/html/test
Is it possible that although mod_rewrite is enabled that it is not working and if so, how can I test it?
On some server implementations, you'll need to wrap it within <IfModule> tags.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
Also check your httpd.conf file to ensure it has:
Options FollowSymLinks
AllowOverride All
It'd also be worth checking to makesure the .htaccess file isn't being overridden by another .htaccess file.
A simple way to test if .htaccess is working
Simply put the following in your .htaccess file:
deny from All
What this does is deny access to your site from everyone. If you are presented with a 403 forbidden when trying to access the site - the .htaccess file is being included. If not - see above.
I use this on my codeigniter setup
RewriteEngine on
# prevent these directories from hitting CI
RewriteCond $1 !^(index\.php|images|assets|robots\.txt|crossdomain\.xml)
# route everything else to the index.php
RewriteRule ^/(.*)$ /index.php/$1 [QSA]
(my setup is done in the virtualhost of .conf and not in .htaccess, though they are usually about the same configuration)
Ok, vague question title, I know. Wasn't sure how to summarize this in one line. I have two applications in my CodeIgniter installation: frontend and admin. There are two front controllers for each that set to the correct application folder. Currently, I use index.php/home for the home page of the frontend and admin.php/home for the home page of the admin panel.
I finally got around to removing index.php from the URL of the frontend. For the admin cp, I would like to use example.com/admin instead of example.com/admin.php. So I basically need to rewrite any uri that has admin as the first segment to admin.php. I figured that adding RewriteRule ^admin/(.*)$ admin.php/$1 to my htaccess would do the trick, but apparently it doesn't... Not completely anyway. I get 404 Page Not Found for every single page in my admin cp. What am I doing wrong?
# Deny OR Allow Folder Indexes.
# Since we disable access to PHP files you
# can leave this on without worries.
# OR better yet, create a .htaccess file in
# the dir you want to allow browsing and
# set it to +Indexes
Options -Indexes
Options +FollowSymLinks
# Set the default file for indexes
DirectoryIndex index.php
<IfModule mod_rewrite.c>
# mod_rewrite rules
RewriteEngine on
# The RewriteBase of the system (if you are using this sytem in a sub-folder).
# RewriteBase /CodeIgniter_1.6.3/
# This will make the site only accessible without the "www."
# (which will keep the subdomain-sensive config file happy)
# If you want the site to be accessed WITH the "www."
# comment-out the following two lines.
# RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
# RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]
# If a controler can't be found - then issue a 404 error from PHP
# Error messages (via the "error" plugin)
# ErrorDocument 403 /index.php/403/
# ErrorDocument 404 /index.php/404/
# ErrorDocument 500 /index.php/500/
# Deny any people (or bots) from the following sites: (to stop spam comments)
# RewriteCond %{HTTP_REFERER} nienschanz\.ru [NC,OR]
# RewriteCond %{HTTP_REFERER} porn\.com
# RewriteRule .* - [F]
# Note: if you are having trouble from a certain URL just
# add it above to forbide all visitors from that site.
# You can also uncomment this if you know the IP:
# Deny from 192.168.1.1
# If the file is NOT the index.php file
RewriteCond %{REQUEST_FILENAME} !index.php
# Hide all PHP files so none can be accessed by HTTP
RewriteRule (.*)\.php$ index.php/$1
# If the file/dir is NOT real go to index
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [QSA,L]
RewriteRule ^admin/(.*)$ admin.php/$1
</IfModule>
# If Mod_ewrite is NOT installed go to index.php
<IfModule !mod_rewrite.c>
ErrorDocument 404 index.php
</IfModule>
You need to add your rule before you index.php routing rule. It's because ^(.*)$ is matching admin/whatever, so your admin rule will never get executed. You should also add -Multiviews to your options so it looks like this:
Options +FollowSymLinks -Multiviews
Then right under RewriteEngine On, add your rule:
RewriteRule ^admin/(.*)$ admin.php/$1 [L]
I just moved a development site from a virtual machine on my PC to a shared webhost in a subdomain and I'm getting a Forbidden error which I think is due to my .htaccess file. Currently I've got it set up like so:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
# Remove www prefix
RewriteCond %{HTTP_HOST} ^www\.mysite\.com$ [NC]
RewriteRule ^(.*)$ http://mysite.com/$1 [L,R=301]
# Redirect to remove .php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
<Files ~ "\.inc$">
Order allow,deny
Deny from all
</Files>
I tried commenting out the RewriteBase line and the "remove WWW prefix" bit which doesn't seem to help. Currently my site resides at mysite.mysharedhost.com and I still need to be able to remove the PHP extensions from my files. Am I missing something important or do you think my error is unrelated to my .htaccess file? Thanks in advance!