htaccess Rewrite Rule not working without index.php in url - .htaccess

I am using apache2 in ubuntu m/c. I have enabled mod_rewrite and changed Allowoveride All in apache2.conf
Now I am trying to install Bug-Genie application in my server
But following .htaccess rules are not work as excepted.
I can access :
http://localhost/roxsoft/thebuggenie-3.2.6/thebuggenie/**index.php**/wiki
But I can't access : --404 error
http://localhost/roxsoft/thebuggenie-3.2.6/thebuggenie/wiki
Here is my .htaccess file:
# .htaccess file for The Bug Genie
# make sure that magic_quotes and register_globals is always off
<IfModule mod_php5.c>
php_flag magic_quotes_gpc off
php_flag register_globals off
</IfModule>
# rewrite rules
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# Example:
# RewriteBase /
# or
# RewriteBase /dev/thebuggenie
# skip all hidden files (starting with a .)
RewriteCond %{REQUEST_URI} \..+$
RewriteCond %{REQUEST_URI} !\.(html|wsdl|json|xml)$
RewriteRule .* - [L]
# redirect to front controller
RewriteRule ^(.*)$ index.php?url=$1 [NC,QSA,L]
</IfModule>
# Stop people accessing directories they shouldn't have access to
RedirectMatch 403 ^/\.svn(/|$)

Try this:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|assets|images|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
Add the folder which contains the JavaScript and CSS to the rewrite condition

Here is the solution I just managed it with. This may help if anyone had a same problem...
I just removed
and added additional conditions in htaccess
here is it:
RewriteCond %{REQUEST_URI} \..+$
RewriteCond %{REQUEST_URI} !\.(html|wsdl|json|xml)$
RewriteCond %{REQUEST_URI} !\.(jpg|png|css|js|php|gif|ttf|woff)$ ---- ADD FILTER CONDITION.
#RewriteRule .* - [L] ---- COMMENT THIS LINE************
# redirect to front controller
RewriteRule ^(.*)$ index.php?url=$1 [NC,QSA,L]

Related

.htaccess issue with url

This url format https://portal.com/pages does not work but this https://portal.com/index.php/pages works.
I want to be able to remove the index.php from the url.
My root .htaccess file is
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off
# First rewrite to HTTPS:
# Don't put www. here. If it is already there it will be included, if not
# the subsequent rule will catch it.
# RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# RewriteEngine On
RewriteRule ^$ public/ [L]
RewriteRule (.*) public/$1 [L]
</IfModule>
While public folder .htaccess file is
<IfModule mod_rewrite.c>
Options -Multiviews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
</IfModule>
Try following rules htaccess file. Make sure your index.php is present inside public folder. Please make sure to clear browser cache before testing your URLs.
root htaccess rules file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [NE,R=301,L]
RewriteCond %{REQUEST_URI} !^/public [NC]
RewriteRule ^(.*)/?$ public/$1 [L]
</IfModule>
Public folder inside htaccess Rules file:
<IfModule mod_rewrite.c>
RewriteOptions InheritBefore
Options -Multiviews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)/?$ index.php?url=$1 [QSA,L]
</IfModule>
Fixes done in OP's attempt:
root htaccess Rules file didn't have https apply rule, so have added it.
Made public applying rule for all kind of urls.
Then in public folder rules file added InheritBefore option to make sure root's file is being inherited to public folder's htaccess rules file.

XCart 1.19.2.1 - enabling SSL

Can someone help me with this one please?
We have a XCart site running version 1.19.2.1 and we would like to force all traffic to HTTPS. The SSL certificate is installed and the .htaccess file looks like this:
DirectoryIndex home.php index.php index.html index.htm
# ErrorDocument 404 /404.php
# Show default error document for 404 errors caused by opening of image/media files.
<Files ~ "\.(gif|jpe?g|png|js|css|swf|ico)$">
ErrorDocument 404 default
ErrorDocument 401 default
# Clean URLs [[[
Options +FollowSymLinks -MultiViews -Indexes
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(ww+\.)?domain\.com
RewriteRule ^(.*) http://www.domain.co.uk/$1 [R=301,L]
<IfModule mod_rewrite.c>
RewriteCond %{ENV:REDIRECT_STATUS} !^401$
RewriteCond %{REQUEST_URI} !^/(payment|admin|provider|partner)/
RewriteCond %{REQUEST_FILENAME} !\.(gif|jpe?g|png|js|css|swf|php|ico)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ dispatcher.php [L]
</IfModule>
# /Clean URLs ]]]
RewriteEngine on
# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php56” package as the default “PHP” programming language.
<IfModule mime_module>
AddType application/x-httpd-ea-php56 .php .php5 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit
I have tried editing the file to redirect all traffic to HTTPS, I get a too many redirects error.
One example that I tried was replacing the entire contents of the .htaccess file with:
ErrorDocument 404 /index.php
RewriteEngine On
Options +FollowSymlinks
RewriteBase /
rewritecond %{http_host} ^domain.co.uk [nc]
rewriterule ^(.*)$ https://www.domain.co.uk/$1 [r=301,nc]
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.domain.co.uk/$1 [R=301,L]
# RewriteRule ^([a-zA-Z0-9\-\%\s\_\.]+)(.htm)$ index.php?page=$1 [L]
##RewriteRule ^([a-zA-Z0-9\-\%\s\_\.]+)\.htm$ index.php?page=$1 [L]
DirectoryIndex index.php
#DirectoryIndex site_closed.html
RewriteEngine on
The above works fine on another XCart site but not this one. Again, I get the too many redirects error.
Anybody have any idea how I can fix it?
Kind regards
James
I had edited the htaccess file but I hadn't edited the https.php file as described here: https://help.x-cart.com/index.php?title=X-Cart:Configuring_HTTPS#Configure_the_HTTPS_server_in_X-Cart
All working now.

CodeIgniter: Remove index.php redirects to the wrong folder

I tried all solutions I found about removing index.php from the URL, but I still cannot make it work properly.
Problem:
the URL http://localhost/rc/index.php/person/find shows the correct page.
the URL http://localhost/rc/person/find shows the WAMP main page (without any image) like it redirects to the root's parent folder.
my configuration:
I created .htaccess is placed in my root directory (/www/rc/.htaccess) which contains the following code:
<IfModule mod_rewrite.c>
# Turn on MOD REWRITE engine
RewriteEngine On
#Remove index.php from the URL
RewriteBase /rc/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
#Also tried the following lines without success
#RewriteRule .* index.php/$0 [PT,L]
#RewriteRule ^(.*)$ index.php/$1 [L,QSA]
</IfModule>
<IfModule !mod_rewrite.c>
# If mod_rewrite is not installed, fire 404 error
ErrorDocument 404 /index.php
</IfModule>
I have also set $config['index_page'] = ''; (in www/rc/application/config/config.php file).
You must put your rule before CodeIgniter's main rule.
Replace your current code by this one (your htaccess has to be in rc folder)
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /rc/
RewriteCond %{THE_REQUEST} \s/rc/index\.php/([^\s]+) [NC]
RewriteRule . %1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
The answer was given by Justin Iurman in the comment of the first answer:
Are you sure mod_rewrite is enabled ? You can check it in your apache config
This can be enabled in httpd.conf file or from the WAMP tray icon.

How can I bypass the .htaccess in a parent directory?

My question is the same as: Zend Framework 2 without Vhost configuration but the solution didn't solve my problem.
I'm getting a customised 404 page.
my project is in a sub-directory, and I believe the .htaccess in the parent directory is stopping it from working.
note: I can't delete that one because there is another project running there
htdocs/.htaccess:
Options -Indexes
Options +SymLinksIfOwnerMatch
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} !^www.domain.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]
RewriteRule ^transcripts/$ https://spreadsheets.google.com/a/ci4tcm.com/ccc? key=0AodnCB9Mr1K1dFFmbGhOc3V4RjBvNzZxSE9EZ1dtSnc&hl=en#gid=0 [R,NC]
# ErrorDocument 404 /pages/404.html
# ErrorDocument 500 /pages/404.html
# ErrorDocument 403 /pages/404.html
# RewriteRule ^css(/)?$ / [R]
# RewriteRule ^download/([A-Za-z0-9.]*)/([A-Za-z0-9.]*)$ /download/$1/$2/ [R]
# RewriteRule ^download/([A-Za-z0-9.]*)/([A-Za-z0-9.]*)/$ /download.php?test=$2&fol=$1
RewriteRule ^download/([A-Za-z0-9.]*)$ /download/$1/ [R]
RewriteRule ^download/([A-Za-z0-9\+.-\s]*)/([A-Za-z0-9\+.-\s]*)$ /download.php?folder=$1&file=$2 [L]
RewriteRule ^download/([A-Za-z0-9.]*)$ /posters/$1/ [R]
RewriteRule ^download/([A-Za-z0-9\+.-\s]*)$ /images/wellbeing_posters/pdfs/$1 [L]
AddHandler server-parsed html
RewriteCond %{HTTP_HOST} ^domain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.domain.com$
RewriteRule ^(.*)$ "http\:\/\/www\.another-domain\.com\/$1" [R=301,L]
# A bunch of redirect 303's here
# 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
htdocs/booking/ < Zend application here > (solution to other question).
RewriteEngine On
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]
so my question is, how do I bypass the parent directory .htaccess rule when the user wants to enter the physical sub directory with the Zend Application?
Your edited question added a whole load of stuff to the .htaccess in the parent folder which changes things somewhat. Assuming you're able to edit that htaccess, the easiest thing to do would be to move the ZF rules into it. Just change any lines that include public and add c-booking before it. So as an example, the last line would look like:
RewriteRule ^c-booking/public/.*$ /c-booking/public/index.php [NC,L]
Also be aware that this is a less secure way to host an app. If you have any non-PHP config files, cache files etc. (things that would normally be outside the web root), make sure they aren't viewable through a browser.

Rewriting urls with Htaccess like filename/param1/param2 etc etc

I'm looking for a solution for the following situation. I'd like to covert the following url
www.example.com/filename.php?p1=1&p2=2 etc
to
www.exmaple.com/filename/1/2 etc
I managed to do this, with index.php, but I'd like to use other file aswell, not only the index. Is it possible? Here's my current code.
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /
# add .php to access file, but don't redirect
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule (.*) $1\.php [L]
RewriteRule ^(filename)/([^/]+)/([^/]+)$ /$1.php?p1=$2&p2=$3 [L,QSA,NC]
ErrorDocument 404 /404.php
# display no errs to user
php_flag display_startup_errors off
php_flag display_errors off
php_flag html_errors off
This works for the php removal. But if I add parameters after it, it gives me error 500
Insert this rule just below RewriteEngine On line:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(filename)/([^/]+)/([^/]+)/?$ /$1.php?p1=$2&p2=$3 [L,QSA,NC]

Resources