redirect of url to "HOME" Page - php

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

Related

how to hide id from the url and make it clean url my directory of .htaccess file is /home/evidhya/public_html/tutorials/.htaccess

I have following url i would like to hide id and make it clean url
https://www.evidhya.com/tutorials/tutorials.php?qid=569/AJAX/Introduction
clean url should be like below url
https://www.evidhya.com/tutorials/AJAX/Introduction
I'm able to achieve using below htaccess code.
https://www.evidhya.com/tutorials/569/AJAX/Introduction
but i don't want 569 id in url
RewriteEngine On
#RewriteBase /KSTA-Webinar/
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
#RewriteRule ^(\d+)/?$ tutorials.php?qid=$1/$2/$1/$3 [L,QSA]
RewriteRule ^([\w.-]+)/?$ get_data.php?qid=$1 [L,QSA]
RewriteEngine on
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{QUERY_STRING} ^title=([^/]+)/([^/]+)/([^/]+)/(.+)$
RewriteRule ^tutorials\.php$ /%1/%2/%4? [R=301]
RewriteRule ^tutorials/([\w+%]{2,50})$ /tutorials.php?qid=$1 [QSA,L]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/$ tutorials.php?qid=$1&user=$2&date=$3
RewriteRule ^([^/]+)/([^/]+)/(.+)$ tutorials.php?qid=$1/$2/$1/$3 [L]
Well, it seems the id is needed to determine the resulting url.
I would do this:
RewriteEngine on
RewriteRule (\d+)/(\w+)/(\w+) tutorials.php?qid=$1/$2/$3 [L]
and place this rule in tutorials/.htaccess.
And when someone goes to https://www.evidhya.com/tutorials/569/AJAX/Introduction it should load https://www.evidhya.com/tutorials/tutorials.php?qid=569/AJAX/Introduction

Too many redirects. Rirect path to subfolder using htaccess

I've ulploaded wordpress in subdirectory to intall. Path of it is
public_html/revslider-standalone
This is full path
http://greenlinerenovations.com/revslider-standalone
When I open this URL in browser, it says too many redirects. Below is my code for .htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^About+$ about.php
RewriteRule ^FAQ+$ faq.php
RewriteRule ^Contact+$ contact.php
RewriteRule ^Gallery+$ gallery.php
RewriteRule ^Areas-we-service+$ cities.php
RewriteRule ^(([^/]+/)*[^.]+)$ servicesparse.php?name=$1
What rule should be added or corrected to install Wordpress on that path ?
Redirects in htaccess file is neccessory so can't remove it. Is there anyway to add new rule and it works ?
Use:
RewriteEngine On
RewriteRule ^About$ about.php [NC,L]
RewriteRule ^FAQ$ faq.php [NC,L]
RewriteRule ^Contact$ contact.php [NC,L]
RewriteRule ^Gallery$ gallery.php [NC,L]
RewriteRule ^Areas-we-service$ cities.php [NC,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(([^/]+/)*[^.]+)$ servicesparse.php?name=$1
With RewriteCond before the last rule RewriteRule

mod_rewrite: how to change the url except the homepage?

I would like to do the following:
redirect /about to /about.php (hide the extension)
redirect /(anything else) to /content.php?p=(anything else)
while keeping the root http://domain.com to /index.php (without showing /index.php)
I tried this:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !-d
RewriteCond %{REQUEST_URI} !-f
RewriteRule "^about$" about.php [NC,L]
RewriteRule ^((/+[A-Za-z0-9\-]+/)*[A-Za-z0-9\-]+)?$ /_content.php?p=$1 [NC,L]
It succeeds to achieve the item 1 and 2, but this also rewrites the root http://domain.com to http://domain.com/_content.php?p=.
What have I done wrong? Thank you for your suggestions!
You can use these rules:
DirectoryIndex index.php
RewriteEngine On
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .+ content.php?p=$0 [QSA,L]

.htaccess multiple rules and exceptions

I have a .htaccess file that has multiple rules to make the url's look "pretty".
This is the file:
RewriteEngine On
RewriteRule ^property/([^/]*)/?([^/]*)/?$ /property.php?ID=$1&Image=$2 [L]
RewriteRule ^property$ /property.php [L]
RewriteRule ^enquire/([^/]*)/?([^/]*)/?$ /enquire.php?ID=$1&Data=$2 [L]
RewriteRule ^enquire$ /enquire.php [L]
RewriteRule ^contact/?$ /contact.php [L]
RewriteRule ^home/?$ /index.php [L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_URI} ^/(property|property/.*|enquire|enquire/.*|contact|contact/.*|home|home/.*)$
RewriteRule ^([^/]*)$ /custompages.php?ID=$1 [L]
The first set of rules works for property, enquire, contact and home.
If the url is not one of these, e.g. www.foo.com/about-us, I want it to call the file custompages?ID=about-us but with this code, it isn't working. I am quite new to using .htaccess files and I can't figure out what the issue is myself.
Your last rule is not correct. Change that to:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ /custompages.php?ID=$1 [L]

Confused about the way this .htaccess rule is supposed to work

I have this in my .htaccess
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^users/([^/]+)/?$ users.php?user=$1 [NC,L]
in my php I have
header("Location: /users/" . $_SESSION['user']);
it loads this into the browser
foo.bar/users/s2xi
which gives me a 404 Not Found error, I can understand up to the part where the directory users doesn't exist, but isn't my RewriteRule supposed to take care of that?
Edit: My complete .htaccess
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^foo\.bar$
RewriteRule (.*) http://www.foo.bar/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule ^([a-zA-Z0-9_\s-]+)/([a-zA-Z0-9_\s-]+)(/)?$ users.php?type=$1&user=$2 [NC,R]
#RewriteRule ^users/?$ users.php [L]
RewriteRule ^([^/]+)/?$ profile.php?user=$1 [NC,L]
#RewriteRule ^users/([^/]+)/?$ users.php?user=$1 [NC,L]
#RewriteRule ^(admin)/(.+)/?$ users.php?user=$1 [NC,L]
RewriteRule ^admin/([^/]+)$ users.php?user=$1 [NC,L]
#error codes
RewriteRule ^/error/([^/]+)/ error.php?code=$1 [NC]
Change your .htaccess to the following:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^users/([^/]+)$ users.php?user=$1 [NC,L]
Also make sure users.php is in a right directory. If it's in root directory, you can use:
RewriteRule ^users/([^/]+)$ /users.php?user=$1 [NC,L]

Categories