htaccess how to remove /home from URL - .htaccess

FOLDERS:
ROOT
pages
home.php
contact.php
.htaccess
htaccess:
# Load files from pages folder
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+pages/([^\s]+) [NC]
RewriteRule ^ %1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (?!^pages/)^(.*)$ /pages/$1 [L,NC]
# Default index.php
DirectoryIndex home.php
RewriteRule ^/?$ /home [L,R]
this works, but when I open localhost:1993, it will change the address to localhost:1993/home. How should I edit the htaccess so that /home does not appear? (only for localhost:1993).
My request is:
localhost:1993 redirect to localhost:1993 (hide /home)
localhost:1993/contact redirect to localhost:1993/contact

RewriteRule ^contact$ pages/contact.php [NC,L,QSA]
or
RewriteRule ^([a-zA-Z0-9-]*)$ pages/$1.php [NC,L,QSA]
query version:
RewriteRule ^([a-zA-Z0-9-]*)/(.*)$ pages/$1.php?query=$2 [NC,L,QSA]

Related

htaccess redirect all request to index but not webroot directory

i have this htaccess file
DirectoryIndex index.php
#enable apache rewrite engine
RewriteEngine on
#set your rewrite base
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
#Deliver the folder or file if it exists on the server directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#Push every request to index.php
#RewriteRule !\.(js|ico|gif|jpg|png|pdf|css|map|swf|flv|xml)$ index.php [QSA,L]
RewriteRule !\.()$ index.php [QSA,L]
RewriteRule ^(webroot)($|/) - [L]
it works but all files with the endings js,ico, ... have direct access.
now i need a htaccess that all request redirect to /
and i think this rule is important
RewriteRule !.()$ index.php [QSA,L]
but with one exception, all request they use the /webroot directory should not redirect (this is the folder with the images, css, js and so on)
I have no idea how to do this. I hope someone can help.
i found a solution:
DirectoryIndex index.php
Options -Indexes
RewriteEngine on
RewriteRule ^\.htaccess$ - [F]
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteRule ^(webroot)($|/) - [L]
RewriteRule !\.()$ index.php [QSA,L]

redirect all URLS to no trailing slash php

My folder structure is, I used htaccess for NO trailing slash at the end of each URL
-job.php to /job
-companies.php to /companies
-about.php to /about
-Admin_jobs(This is Admin Folder)
and My .htaccess file is
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{THE_REQUEST} \s(.+?)/+[?\s]
RewriteRule ^(.+?)/$ /$1 [R=301,L]
RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteCond %{HTTP_HOST} ^sitename.com [NC]
#redirect to www
RewriteRule ^(.*)$ http://www.sitename.com/$1 [L,R=301]
.
I am trying to access my Admin_jobs/ folder then it was redirecting to my main site, www.example.com. I cannot access to My admin pages. Anybody is there to help me.

Show url of index page with .htaccess

I have googled around and can't find an answer to my question so her I am. How can I force, with .htaccess, the filename of the index page to show when accessed by just the domain.
So if http://example.com is typed in http://examples.com/home will show in the address bar.
I have already used .htaccess to set home.php as the index page and remove the .php extension.
current .htaccess
DirectoryIndex home.php
RewriteEngine on
#add php extension
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteCond %{REQUEST_URI} !^/(phpscripts|js)/ [NC]
RewriteRule ^([^/]*)(?:/(.*?|))?/?$ /$1.php?$2 [L]
# redirect to .php-less link if requested directly
RewriteCond %{THE_REQUEST} ^[A-Z]+\s.+\.php\sHTTP/.+
RewriteCond %{REQUEST_URI} !^/(phpscripts|js)/ [NC]
RewriteRule ^(.*)\.php /$1 [R=301,L]
#redirect www to non-www
RewriteCond %{HTTP_HOST} ^www\.^([a-zA-Z0-9_-]+)$ [NC]
RewriteRule ^(.*)$ http://^([a-zA-Z0-9_-]+)$1 [L,R=301]
#remove trailing slash
RewriteRule ^(.*)/$ /$1 [L,R=301]
You want
RewriteRule ^$ /home [L,R=301]
This should catch both http://example.com and http://example.com/, and send them to http://example.com/home

htaccess redirect from domain.com/index.php?page=about to domain.com/about

I've upgraded an old website and wanted to redirect all the old pages to the new ones. the old website used the index page and a query string to server the relevant content.
here is the new htaccess file. the problem in question is getting the redirect to work. also if you can steamline this file:
Options +FollowSymLinks
Options +Indexes
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.domain.co.uk$ [NC]
RewriteRule ^(.*)$ http://domain.co.uk/$1 [R=301,L]
#if its not a directory
RewriteCond %{REQUEST_FILENAME} !-d
#and it has a trailing slash then redirect to URL without slash
RewriteRule ^(.+)/$ /$1 [L,R=301]
#this removes php extention
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
# stops you accessing url with.php
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([^.?\ ]+)\.php
RewriteRule ^([^.]+)\.php(/.+)?$ /$1%{PATH_INFO} [R=301]
RewriteRule ^news/([^/]*)/([^/]*)$ /news?id=$1&title=$2 [L]
Redirect 301 index?page=about http://domain.co.uk/about
ErrorDocument 404 http://domain.co.uk/404
The apropiate rule to redirect domain.com/index.php?page=about to domain.com/about is the following
RewriteRule ^index\.php$ %{QUERY_STRING} [C]
RewriteRule page=(.*) /$1? [R=301,L]

.htaccess doesn't work

I have the following .htaccess file:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^mydomain.com
RewriteRule (.*) http://www.mydomain.com/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^mykeyword$ news.php [L,QSA,NC]
However, when I open the news.php, the url is still the same, that is www.mydomain.com/news.php instead of www.mydomain.com/mykeyword
I make the following test:
RewriteEngine on
RewriteRule ^test\.html$ test.php [L]
I upload 2 files on my server, test.html and test.php and after I type www.mydomain.com/test.html, my php page was displayed, so that mean that I have no problem with my settings. What on earth I am doing wrong???
Any help will be deeply appreciated.
Regards,Zoran
Change your .htaccess to this:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(mydomain\.com)$ [NC]
RewriteRule ^(.*)$ http://www.%1/$1 [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+news\.php [NC]
RewriteRule ^ mykeyword [R=301,L]
RewriteRule ^mykeyword/?$ news.php [L,NC]
The rewrite rule translates from the URL supplied by the user to the URL seen by the server. Try browsing to www.mydomain.com/mykeyword - you should see the page news.php.

Resources