Priority redirecting using .htaccess - apache

I want to set a priority in my .htaccess.
Ok, I've got folders on my root project, schema:
-root:
-core
-includes
-pages:
- profile.php
-etc
-support
-infractions
-.htaccess
and what I want to do is:
If the URL is like https://example.com/support, show the /support/index.php.
I've tried -Indexes option but it doesn't works or doesn't meet my needs.
My .htaccess is like:
Options +FollowSymlinks
Options +Indexes
Options -MultiViews
RewriteEngine On
RewriteCond %{HTTP_HOST} ^fenixcms\.com [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://fenixcms.com/$1 [R,L]
RewriteBase /
DirectoryIndex pages/index.php
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^alert/([^/\.]+)/?$ pages/alert.php?id=$1 [L]
RewriteRule ^player/([^/\.]+)/?$ pages/profile.php?name=$1 [L]
RewriteRule ^forums/new_topic/([^/\.]+)/?$ /forums/new_topic.php?c=$1 [L]
RewriteRule ^forums/topics/([^/\.]+)/posts/edit/([^/\.]+)/?$ /forums/edit_post.php?tid=$1&pid=$2 [L]
RewriteRule ^forums/topics/([^/\.]+)/posts/new/?$ /forums/new_post.php?tid=$1 [L]
RewriteRule ^forums/topics/([^/\.]+)/posts/reply_to_id/([^/\.]+)/?$ /forums/new_quote.php?tid=$1&pid=$2 [L]
RewriteRule ^forums/topics/([^/\.]+)/edit/?$ /forums/edit_topic.php?tid=$1 [L]
RewriteRule ^forums/topics/([^/\.]+)/?$ /forums/topic.php?id=$1 [L]
RewriteRule ^forums/topics/([^/\.]+)/posts/delete/([^/\.]+)/?$ /forums/delete_post.php?tid=$1&pid=$2 [L]
RewriteRule ^forums/categories/([^/\.]+)/?$ /forums/categories.php?s=$1 [L]
RewriteRule ^forums/posts/([^/\.]+)/?$ /forums/posts.php?pid=$1 [L]
RewriteRule ^forums/([^/\.]+)/?$ /forums/$1.php [L]
RewriteRule ^revisions/([^/\.]+)/?$ pages/revisions.php?action=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^\.]+)/([^/\.]+)/?$ /$1/$2.php [L]
RewriteRule ^([^\.]+)/?$ /$1/index.php [NC,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ pages/$1.php [NC,L]

Related

.htaccess not including https or http in address bar

How can I force domain.co.nz to redirect to https://domain.co.nz?
Currently using:
I am currently using the following .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /sub-folder/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /sub-folder/index.php [L]
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.*)$ [NC]
RewriteRule (.*) https://%1%{REQUEST_URI} [L,R=301]
RewriteRule ^([^.]+[^/])$ $1/ [L,R=301]
</IfModule>
Change the order:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.*)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [NE,L,R=301]
RewriteRule ^([^.]+[^/])$ $1/ [L,R=301]
RewriteBase /sub-folder/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /sub-folder/index.php [L]
</IfModule>
Redirect first !

htaccess rewrite doesn't work on 2nd level rewrite

I have the following lines in my .htaccess
Options +FollowSymlinks
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ seo.php?p=$1 [L]
RewriteRule ^seo/site:(.*)$ seo.php?p=seo&domain=/$1&status=seo [QSA]
RewriteRule ^seo/(.*)$ seo.php?p=seo&domain=/$1&status=seo [L]
RewriteRule ^admin/page:(.*)$ seo.php?p=admin&page=/$1 [L]
RewriteRule ^webagent/page:(.*)$ seo.php?p=webagent&page=/$1 [L]
RewriteRule ^setlang:(.*)$ seo.php?setlang=/$1 [L]
RewriteRule ^(.*)/setlang:(.*)$ seo.php?p=/$1&setlang=/$2 [L]
</IfModule>
The problem is that only first Rule works normal. it takes pages from currently defined folder in php
When i try to open
seo/domain.com
it doesn't work but when i open
seo.php?p=seo&domain=domain.com&status=seo
works very well.
Where i go wrong with this .htaccess file.
Have your rules like this:
Options +FollowSymlinks
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# skip all files and directories from rewrite rules below
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
RewriteRule ^seo/site:(.*)$ seo.php?p=seo&domain=/$1&status=seo [L,QSA]
RewriteRule ^seo/(.*)$ seo.php?p=seo&domain=/$1&status=seo [L,QSA]
RewriteRule ^admin/page:(.*)$ seo.php?p=admin&page=/$1 [L,QSA]
RewriteRule ^webagent/page:(.*)$ seo.php?p=webagent&page=/$1 [L,QSA]
RewriteRule ^setlang:(.*)$ seo.php?setlang=/$1 [L,QSA]
RewriteRule ^(.*)/setlang:(.*)$ seo.php?p=/$1&setlang=/$2 [L,QSA]
RewriteRule ^(.*)$ seo.php?p=$1 [L,QSA]
</IfModule>

Apache Htaccess rewrite rules

I have to write a htaccess to rewrite the links as follows and also a redirection of 404
error pages to my sites root (home page)
www.example.com/index.php?page=find&name=detail&id=109&cid=8
www.example.com/index.php?page=find&name=detail&id=109
www.example.com/index.php?page=find&name=detail
www.example.com/index.php?page=find
should be rewritten to
www.example.com/find/name/detail/id/109/cid/8
www.example.com/find/name/detail/id/109
www.example.com/find/name/detail
www.example.com/find
Your htaccess rules,
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?file=$1 [L,QSA]
RewriteRule ^([a-zA-Z]+)/page/([a-zA-Z]+)/id/([0-9]+)/cid/([0-9]+)/$ index.php?page=find&name=detail&id=109&cid=8 [L]
RewriteRule ^([a-zA-Z]+)/page/([a-zA-Z]+)/id/([0-9]+)/$ index.php?page=find&name=detail&id=109 [L]
RewriteRule ^([a-zA-Z]+)/page/([a-zA-Z]+)/$ index.php?page=find&name=detail [L]
RewriteRule ^([a-zA-Z]+)/$ index.php?page=find [L]
</IfModule>
Try:
RewriteEngine On
RewriteRule ^find$ index.php?page=find [L,QSA]
RewriteRule ^(find)/([^/]+)/([^/]+)(.*)$ /$1$4?$2=$3 [L,QSA]
FallbackResource /
Try this code:
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule (.*)/([a-zA-z0-9]*)/(.*)/([a-zA-z0-9]*)/(.*)/([a-zA-z0-9]*)/(.*)/([a-zA-z0-9]*)/(.*)\.html index.php?itfpage=$1&$2=$3&$4=$5&$6=$7$8=$9 [L]
RewriteRule (.*)/([a-zA-z0-9]*)/(.*)/([a-zA-z0-9]*)/(.*)/([a-zA-z0-9]*)/(.*)\.html index.php?itfpage=$1&$2=$3&$4=$5&$6=$7 [L]
RewriteRule (.*)/([a-zA-z0-9]*)/(.*)/([a-zA-z0-9]*)/(.*)\.html index.php?itfpage=$1&$2=$3&$4=$5 [L]
RewriteRule (.*)/([a-zA-Z]*)/(.*)\.html index.php?itfpage=$1&$2=$3 [L]

Merge two .htaccess codes

I have two .htaccess , the fist .htaccess locate in the root directory which is www folder and the 2nd .htaccess locate in folder called forum
the .htaccess codes in www folder cannot work with the .htaccess codes in the forum folder
what i am working on is how to merge both htaccess to be in the root directory www
.htaccess in the www directory
Options +FollowSymlinks -MultiViews
RewriteEngine on
RewriteCond %{HTTP_HOST} ^site\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.site\.com$
RewriteRule ^/?$ "http\:\/\/www\.site\.net\/" [R=301,L]
RewriteCond %{HTTP_HOST} ^(?:www\.)?site\.com$ [NC]
RewriteRule ^(.*)$ http://www.site.net/$1 [R=301,L]
.htaccess in the forum directory
#RewriteEngine On
RewriteRule ^site-t(.*).html showthread.php?t=$1 [L]
RewriteRule ^site-f(.*) forumdisplay.php?f=$1 [L]
RewriteRule ^f(.*)-(.*).html forumdisplay.php?f=$1 [L]
RewriteRule ^site-u(.*).html member.php?u=$1 [L]
RewriteRule ^index.php$ http://%{http_host}/ [R=301,L
RewriteRule ^t(.*).html showthread.php?t=$1 [L]
RewriteRule ^f(.*).html forumdisplay.php?f=$1 [L]
RewriteRule ^post(.*)-(.*) showpost.php?p=$1&postcount=$2 [L]
RewriteRule ^u(.*).html member.php?u=$1 [L]
RewriteRule archive/t-(.*) archive/index.php/t-$1 [L]
RewriteRule tags/(.*).html tags.php?tag=$1 [L]
RewriteEngine on
# This file is only needed if you have set the Forum Component URL in your admincp and you are
# using the mod_rewrite option for friendly urls. If this is the case, copy this file
# to your forum component stub directory.
# If you are having problems or are using VirtualDocumentRoot, uncomment this line and set it to your forum component directory.
# RewriteBase /forum-stub-directory/
# If you are having problems with the rewrite from content/ to content.php, uncomment this line to turn MultiViews off.
# Options -MultiViews
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
# Forum
RewriteRule ^threads/.* showthread.php [QSA]
RewriteRule ^forums/.* forumdisplay.php [QSA]
RewriteRule ^members/.* member.php [QSA]
##################################################
RewriteEngine on
RewriteRule ^f.txt vbmaps.php?cat=d [L]
RewriteRule ^t([0-9]+).txt vbmaps.php?rss=d&page=$1 [L]
RewriteRule ^tag([0-9]+).txt maptag.php?rss=d&page=$1 [L]
RewriteRule ^t([0-9]+).txt vbmaps.php?rss=d&page=$1 [L]
RewriteRule ^tag([0-9]+).txt maptag.php?rss=d&page=$1 [L]
RewriteRule ^forums maps.php?cat=d [L]
RewriteRule ^thread([0-9]+) maps.php?rss=d&page=$1 [L]
RewriteRule ^forums.xml maps.php?cat=d
RewriteRule ^thread([0-9]+).xml maps.php?rss=d&page=$1 [L]
RewriteRule ^t([0-9]+)\-([0-9]+)\.html$ showthread.php?t=$1&page=$2 [L]
RewriteRule ^f([0-9]+)\-([0-9]+)\.html$ forumdisplay.php?f=$1&page=$2 [L]
RewriteRule ^post([0-9]+)\.html$ showthread.php?p=$1#post$2 [L]
RewriteRule ^t(.*).html showthread.php?t=$1 [L]
RewriteRule ^u(.*).html member.php?u=$1 [L]
RewriteRule ^f(.*).html forumdisplay.php?f=$1 [L]
RewriteRule ^f(.*)-t(.*) showthread.php?t=$1 [L]
RewriteRule ^t([0-9]+)\-([0-9]+)$ showthread.php?t=$1&page=$2 [L]
RewriteRule ^f([0-9]+)\-([0-9]+)$ forumdisplay.php?f=$1&page=$2 [L]
RewriteRule ^post([0-9]+)$ showthread.php?p=$1#post$2 [L]
RewriteRule ^t([0-9]+)$ showthread.php?t=$1 [L]
RewriteRule ^u([0-9]+)$ member.php?u=$1 [L]
RewriteRule ^f([0-9]+)$ forumdisplay.php?f=$1 [L]
RewriteRule ^t([0-9]+)\-([0-9]+)$ showthread.php?t=$1&page=$2 [L]
RewriteRule ^f([0-9]+)\-([0-9]+)$ forumdisplay.php?f=$1&page=$2 [L]
RewriteRule ^post([0-9]+)$ showthread.php?p=$1#post$2 [L]
RewriteRule ^t([0-9]+)$ showthread.php?t=$1 [L]
RewriteRule ^u([0-9]+)$ member.php?u=$1 [L]
RewriteRule ^f([0-9]+)$ forumdisplay.php?f=$1 [L]
RewriteEngine On
RewriteRule ^t(.*).html showthread.php?t=$1 [L]
RewriteRule ^f(.*).html forumdisplay.php?f=$1 [L]
RewriteRule ^u(.*).html member.php?u=$1 [L]
RewriteRule ^(.*)-post(.*).html showpost.php?p=$1&postcount=$2 [L]
RedirectMatch 301 thread(.*).html$ http://www.site.net/vb/showthread.php?t=$1
#########################################################
RewriteRule ^((urllist|sitemap_).*\.(xml|txt)(\.gz)?)$ vbseo_sitemap/vbulletin_sitemap_index.xml.gz [L]

redirect all non www to www. for Cakephp site

Hi allm i'm having some issues in redirecting the non www pages to the www. pages for my cakephp site.
I've tried
Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^domain.com [nc]
rewriterule ^(.*)$ http://www.domain.com/$1 [r=301,nc]
but it doesn't seem to work.
My cakephp app resides in a subfolder. eg. www.domain.com/my.
i've added the above code to the root folder, www.domain.com/
any suggestions? thanks?
*update
This my .htaccess file
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain\.com$ [NC]
RewriteRule ^.*$ http://www.domain.com%{REQUEST_URI} [R=301,L]
i'm getting an extra webroot/index.php?url= inserted into the url. Instead of www.domain.com/my/apple, i'm getting www.domain.com/my/webroot/index.php?url=apple
thanks to all once again.
Your code is not quite right. See below.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain\.com$ [NC]
RewriteRule ^.*$ http://www.domain.com%{REQUEST_URI} [R=301,L] # <-- Mind the 'L'!
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
if domain is .co.uk
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain\.co\.uk$ [NC]
RewriteRule ^.*$ http://www.domain.co.uk%{REQUEST_URI} [R=301,L]
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.domain\.com [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app/webroot/$1 [QSA,L]
I have tried the below code below and it worked for me:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^gigsadda\.com$ [NC]
RewriteRule ^.*$ http://www.gigsadda.com%{REQUEST_URI} [R=301,L]
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>