how set mod_rewrite by ip all pages - apache

i use friendly url names like myservice/controller/action/key/value/key/value etc. Everything is ok when i am running my server on remote hosting. But now i tried run server on my linux and i have a access by ip. My mod_rewrite rules doesn't work. Could someone tell me how can i change this ?
my old rules working on remote hosting with domain
rewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
Options +FollowSymLinks -Indexes -MultiViews
And this is my new rules not working
rewriteEngine On
RewriteCond %{REMOTE_ADDR} !^192\.168\.1\.104$
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

Ok i tried many times and this rules works fine
rewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
Options +FollowSymLinks -Indexes -MultiViews
But in vhost in apache2/available-sites i had to add
<Directory /var/www/html>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
Thanx for help

Related

Removing index.php from the URI in Codeigniter 3

I have done all the said solutions to remove 'index.php' from the URI. The procedure I took is as below:
In .htaccess:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
In config.php
the base_url is set to
$config['base_url'] = 'https://trawellmate.com/';
Removed index.php from
$config['index_page'] = '';
These are the suggested solutions. But nothing worked. I am using SSL and all non requests are redirected to https://trawellmate.com. Following is the lines added to achieve in .htaccess:
#FORCE NON-WWW REDIRECT
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.*)$ [NC]
RewriteRule (.*) https://%1%{REQUEST_URI} [L,R=301]
Earlier with non SSL(in development mode in localhost) it was working fine. Since, we are about to go live, a quick help will be deeply appreciated.
You may try to use the following rules. It worked for me.
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [OR]
RewriteCond %{HTTP_HOST} ^yourwebsite\.com$ [NC]
RewriteRule ^ https://www.yourwebsite.com%{REQUEST_URI} [R=301,L,NE]
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /index\.php(/[^\ ]*)?\ HTTP/
RewriteRule ^index\.php(/(.*))?$ yourwebsite.com/$2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
Allow overriding htaccess in Apache Configuration (Command)
sudo nano /etc/apache2/apache2.conf
and edit the file & change to
AllowOverride All
Below .htaccess configuration works for me
RewriteEngine on
RewriteBase /<app_directory>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /<app_directory>/index.php/$1 [L]
I've placed the .htacess file in /var/www/html ie. Parallel to application directory
Hope you have enabled mod_rewrite module for apache, Also add below block in virtualhost file(000-default.conf) of apache. Please restart server after changes.
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>

How to put my .htaccess in my virtualhost?

I would like to know if it's possible to put .htaccess instructions directly in my virtualhost.
My .htaccess :
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
I try on my virtualhost (some instructions are deliberately deleted for this topic) :
<VirtualHost *:80>
ServerName domain.dev
ServerAlias www.domain.dev
<Directory /www/htdocs/domain/html/>
Options -Indexes FollowSymLinks MultiViews
AllowOverride All
</Directory>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
</IfModule>
</VirtualHost>
But my browser responds :
Bad Request
Your browser sent a request that this server could not understand.
It's work with :
<Directory /www/htdocs/domain/html/>
Options -Indexes FollowSymLinks
AllowOverride All
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
</Directory>

.htaccess rewrite rule with DocumentRoot subdomain

I'm trying to implement some htaccess rewrite rules. However in not a pro in htaccess.
I have a subdomain gateway in (as described in: .htaccess and rewrite sub domains)
Now i would like to use SEO friendly URL's. The gateway has some subfolders i.e. email in this case.
http://gateway.example.com/email/Param1/Param2/
This url should be rewritten to http://gateway.example.com/email/index.php?hash=Param1&hash2=Param2.
In the email folder I have created a .htaccess file with the following contents:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.* - [L]
RewriteRule ^/(.*)/(.*)/ index.php?hash=$1&hash2=$2
When requesting the http://gateway.example.com/email/Param1/Param2/ i'm now getting a 404. What is wrong with the rule?
You should do it this way
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/?([^/]*)/([^/]*)/ /email/index.php?hash=$1&hash2=$2 [L]
you can try this.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^/([^/]*)/([^/]*)/ index.php?hash=$1&hash2=$2
*you need to configure apache(httpd) to accept UrlRewrite by changing AllowOverride from non to all like this :
<Directory "/var/www/html">
Options Indexes FollowSymLinks
AllowOverride all
Order allow,deny
Allow from all
</Directory>

Unable to get .htaccess working

As an experienced web developer, I feel like an idiot posting this. Somehow I tend to have issues with .htaccess. I'm trying to route all requests within /wiki to my index.php with the following...
RewriteEngine On
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ./ /index.php [L]
Virutal host:
<VirtualHost *:80>
ServerName mysite.local
DocumentRoot "/var/www/mysite/public_html"
<Directory "/var/www/mysite/public_html">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
I'm trying to access http://mysite.local/wiki/asdf and getting a 404 error.
Apache's error log shows nothing
If /wiki is an existing folder in your public_html root folder, and your index.php file is in the wiki folder, then you can give the following a try:
RewriteEngine On
RewriteBase /wiki
RewriteRule index\.php - [F,L]
RewriteCond %{REQUEST_URI} !-f
RewriteCond %{REQUEST_URI} !-d
RewriteRule .* index.php [L]
If the wiki folder does not exist, and you're doing all the work at the root:
RewriteEngine On
RewriteBase /
RewriteRule index\.php - [F,L]
RewriteCond %{REQUEST_URI} !-f
RewriteCond %{REQUEST_URI} !-d
RewriteRule wiki/(.*) index.php/$1 [L]
Now give this a try! To rewrite non-existence /wiki and /wiki/ and /wiki/$var into /index.php:
RewriteCond %{REQUEST_URI} ^/wiki/?
RewriteCond %{REQUEST_FILENAME} !-f [OR]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) /index.php
I ended up needing what the Yii Framework uses...
RewriteEngine On
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward it to index.php
RewriteRule . index.php

example.com/dir/index.php works but example.com/dir/ doesn't

I'm on Linux CENT OS 6.3 with latest php and latest apache,
on httpd.conf I got
DirectoryIndex index.php
<Directory "/var/www/html">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
When I go to:
example.com/mydir/index.php
it works, but it does not work for example.com/mydir/
it is a problem to me.
Actually might it have to do with something in the .htaccess file:
RewriteEngine on
options +FollowSymLinks
RewriteRule ^([A-Za-z-0-9-_.]+)/pics/([A-Za-z-0-9-_.]*.*)?$ users/$1/pics/$2
#levanta de users/pics
RewriteRule ^([A-Za-z-0-9-_.]+)/vids/([A-Za-z-0-9-_.]*.*)?$ users/$1/vids/$2
#levanta de users/vids
RewriteCond %{REQUEST_URI} ^.*\.(html|png|jpg|gif|jpeg|css|js)
RewriteRule ^([^/]+)(/(.*))?$ - [L]
RewriteCond %{REQUEST_URI} !settingsd
RewriteRule ^settings settingsd/settings.php
RewriteRule ^lists/ master/index.php
RewriteRule ^lists/(.*)$ $1
RewriteRule ^index\.(php) master/index.php
#levanta de master/
RewriteCond %{REQUEST_URI} !.*\.(css|js|php)|pokes|settings|subgram
RewriteRule ^([A-Za-z-0-9-_.]+)?$ master/$2
RewriteCond %{REQUEST_URI} !pokesd
RewriteRule ^pokes(.*)$ pokesd/$1
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !pokes|subgram
RewriteRule ^([A-Za-z-0-9-_.]+)/([A-Za-z-0-9-_.]+.php)?$ master/$2
#levanta de master/
RewriteRule ^messages/ messages.php
RewriteRule ^notes/me/ notes/notes.php
RewriteRule ^notes/drafts/ notes/notes_drafts.php
RewriteRule ^notes/tagged/ notes/notes_tagged.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !photos_albums|photos_stream
RewriteRule ^([A-Za-z-0-9-_.]+)/photos $1/view_photos.php
RewriteRule ^([A-Za-z-0-9-_.]+)/photos_albums $1/view_photos.php?sk=photos_albums
RewriteRule ^([A-Za-z-0-9-_.]+)/photos_stream $1/view_photos.php?sk=photos_stream
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([A-Za-z-0-9-_.]+)/friends $1/view_friends.php
RewriteCond %{REQUEST_URI} !listsd
RewriteRule ^bookmarks/lists(.*)$ bookmarks/listsd/$1
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^v(.*)$ v/video_embed.php?sbid=$1
RewriteCond %{REQUEST_URI} !.*\.(css|js|php)|notes/me/|notes/drafts/|notes/tagged/
RewriteRule ^notes/ notes/
RewriteRule ^r.php$ gvrrgvrr45.php$1
It has to do with a rule in there because when I strip it all and upload to the server clean it suddenly works, that same .htaccess was working in Windows but isn't working in this config.
It's not related to .htaccess . It's your Apache setting ( /etc/httpd.conf )
Check your DirectoryIndex directive settings. It should have at least index.php to support your needs :
DirectoryIndex index.html index.htm index.shtm index.shtml index.php
or remove any entries that does not fit your need.