I'm in the process of building an api and want to redirect all requests to v1/index.php
My folder structure is;
-htdocs
--v1
----index.php
This is my htaccess atm
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 want all requests sent to api.example.co.uk to go to v1/index.php
I want all requests sent to api.example.co.uk to go to v1/index.php
You can have this rule in root .htaccess:
RewriteEngine On
RewriteCond %{HTTP_HOST} =api.example.co.uk
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ v1/index.php [L]
If you point you domain to /htdocs/v1/ folder and place inside with your index.php this .htaccess file it will redirect any request to index.php
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ /index.php [L]
Related
I want to redirect to the main domain if a directory(any) exists
but does not have an index file(index.php/index.html), How to do that? I tried the below code but does not work.
Options +FollowSymlinks -Indexes
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ %1 [R=301,L]
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{DOCUMENT_ROOT}/$1/index.php !-f [OR]
RewriteCond %{DOCUMENT_ROOT}/$1/index.html !-f
RewriteRule ^(.+)/$ / [L,R]
This will redirect a directory request to / if the /index file doesn't exist in that folder.
Trying to remove index.php from and just resolve to the subdirectory name which works, however after making the change to .htaccess file all the other pages redirect to the subdirectory.
For example:
Changed: site.com/subdir/index.php to site.com/subdir/ but then site.com/subdir/page?id=4 resolves to site.com/subdir/
.htaccess:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteBase /subdir/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
How to write this rule so that only index.php resolves to /subdir/ and not the other pages within that directory?
You can use these rules in site root .htaccess:
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s(.*/)index\.php[?\s] [NC]
RewriteRule ^ %1 [L,R=301,NE]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ subdir/index.php [L]
So I have this task, where I have to make basically two webpages under one domain. Main page always have to go through index.php. Except if / subdirectory (under subdirectory there is another webpage) - then works with subdirectory
Example:
example.com -> goes to index.php
example.com/subdirectory ->goes to /subdirectory/index.php
example.com/subdirectory/peter -> goes to /subdirectory/peter/
example.com/example2 -> goes to index.php
This is what I have managed so far:
#If
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteCond %{REQUEST_URI} !/subdirectory/index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# rewrite
RewriteRule ^(.*)$ /forums/$1 [L]
# IF
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteCond %{REQUEST_URI} !/index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# rewrite
RewriteRule ^(/)?$ index.php [L]
Honestly I am out of ideas...
Found out how to do it:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !/forums
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
atleast for now its workin.
When i type anything beyond my url path Eg: http://example.com/doctorlist/ngffghf5235235 , I want it to get redirected to my home page i,e.. http://example.com . How can I do it .
I have my .htacess as follow
RewriteEngine on
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !/(css|images|js)/
RewriteRule ^home/(.*)$ index.php [QSA]
RewriteRule ^doctorlist/(.*)$ innerpage.php [QSA]
RewriteRule ^appointment-list/(.*)$ detailspage.php?doc_id=$1 [QSA]
RewriteRule ^register-plus-appointment-form/(.*)$ register_plus_appointment_form.php?doc_id=$1&time_id=$2&date=$3&time=$4 [L,QSA]
RewriteRule ^appointment-form/(.*)$ appoint_form.php [L,QSA]
RewriteRule ^appointment-confirm-form/(.*)$ appointment_form.php [L,QSA]
to redirect every request to a certain page, eg index.php
RewriteRule (.*) /index.php [L]
hope this helps
According to your tags, I assume you need this for your Zend Framework application. So this will do the job :
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
See : http://framework.zend.com/manual/1.12/en/zend.application.quick-start.html
The following RewriteRule works correctly
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://domain.com/$1/ [L,R=301]
until I place this one just right below
RewriteRule ^([a-z0-9]+)/$ /profile/company-profile.php?cname=$1 [NC,L]
Now every domain.com/something-here goes to the company-profile.php
How can I fix this ?
Firstly, the domain.com/login takes you to the index.php of the login folder.
When I type the second RewriteRule, if I write domain.com/login again it shows (in the background) the company-profile.php?cname=login
I would recommend to use this:
RewriteEngine On
RewriteBase /
# redirect company specific request
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z0-9\-_]+)/?$ profile/company-profile.php?cname=$1 [NC,L]
# redirect all others
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{REQUEST_URI} !/?$
RewriteRule ^(.*)$ http://domain.com/$1/ [L,R=301]