htaccess exception from RewriteRule .* index.php [QSA] - .htaccess

in typo3 htacces finish all redirection by RewriteRule .* index.php [QSA],
but I need create PromoCode foldier with php aplication and own index.php work under adres www.domainname.com/PromoCode. So i need to add exception into htacces, but not sure how...
RewriteRule ^rss\/([^\.]+).xml$ fileadmin/rss/$1.xml [QSA,L]
#RewriteRule ^fileadmin\/(.*)$ fileadmin/$1 [QSA,L]
# SPECIAL
RewriteRule ^ua-ru/links807835.php fileadmin/links807835.php [QSA,L]
# PAGING
RewriteRule ^(.*)(?!order\/.*)\/order\/([^-]+)-([^\/]+)(.*)$ $1$4?pg_order=$2&pg_by=$3 [QSA,L]
RewriteRule ^(.*)(?!order\/.*)\/order\/([^\/]+)(.*)$ $1$3?pg_order=$2 [QSA,L]
RewriteRule ^(.*)(?!page\/.*)\/page\/([^\/]+)(.*)$ $1$3?pg_page=$2 [QSA,L]
RewriteRule ^(.*)(?!size\/.*)\/size\/([^\/]+)(.*)$ $1$3?pg_size=$2 [QSA,L]
# FAQ
RewriteRule ^(.*)(?!faq\/.*)\/faq\/([^\/]+)(.*)$ $1$3?faq=$2 [QSA,L]
# GALLERY
RewriteRule ^(.*)(?!gallery\/.*)\/gallery\/([^\/]+)(.*)$ $1$3?gallery=$2 [QSA,L]
# ARTICLE
RewriteRule ^(.*)(?!article\/.*)\/article\/([^\/]+)(.*)$ $1$3?article=$2 [QSA,L]
# PRODUCT
RewriteRule ^(.*)(?!product\/.*)\/product\/([^\/]+)(.*)$ $1$3?product=$2 [QSA,L]
# EVENT
RewriteRule ^(.*)(?!event\/.*)\/event\/([^\/]+)(.*)$ $1$3?event=$2 [QSA,L]
# MATERIAL
RewriteRule ^(.*)(?!material\/.*)\/material\/([^\/]+)(.*)$ $1$3?material=$2 [QSA,L]
# CATEGORY
RewriteRule ^(.*)(?!category\/.*)\/category([^\/]+)([^\/]+)(.*)$ $1$3?category=$2 [QSA,L]
# LANGUAGE
RewriteRule ^([^\/]*)\/$ $1?id=$1 [QSA]
RewriteRule ^([^\/]*)$ $1?id=$1 [QSA]
#RewriteRule ^([^\/]*)[\/]{0,1}(.*)$ $2?lang=$1 [QSA]
RewriteRule ^([^\/]*)[\/]{0,1}(.*)$ ?lang=$1 [QSA]
# PAGE
RewriteRule ^[\/]{0,1}([^\/]+)[\/]([^\/]+)[\/]([^\/]+)[\/]{0,1}(.*)$ ?id=$3&pid1=$2&pid2=$1 [QSA]
RewriteRule ^[\/]{0,1}([^\/]+)[\/]([^\/]+)[\/]{0,1}(.*)$ ?id=$2&pid1=$1 [QSA]
RewriteRule ^[\/]{0,1}([^\/]+)[\/]{0,1}(.*)$ ?id=$1 [QSA]
# FINISH
RewriteCond %{REQUEST_URI} !^/PromoCode/
RewriteRule .* index.php [QSA]

Before the RewriteRule .* index.php line, add this condition:
RewriteCond %{REQUEST_URI} !^/promocode/
make the /promocode/ folder whatever the foldername is that you want to make an exception for.

Related

.htaccess RewriteRule file in another folder

I have a two-part site, the first part on the home page, I have one .htaccess file and I use these htaccess commands to rewrite their files
RewriteRule ^sitemap-([0-9]+).xml$ sitemap-xml.php?page=$1
The other part of the site is on folder called bio, and i use these htaccess commands to rewrite their files
RewriteRule ^/bio/([0-9]+)/(.*)$ /bio/show_person.php?id=$1&url=$2 [QSA,L]
but the bio RewriteRule dose not work, how can i fix it
here is my complete htaccess
RewriteEngine On
RewriteBase /bio/
RewriteRule ^([0-9]+)/(.*)$ show_person.php?id=$1&url=$2 [QSA,L]
RewriteRule ^job-([0-9]+)/$ show_job.php?id=$1 [QSA,L]
RewriteRule ^nationality-([0-9]+)/$ show_nationality.php?id=$1 [QSA,L]
RewriteRule ^borg-([0-9]+)/$ show_borg.php?borg=$1 [QSA,L]
RewriteRule ^birth-([0-9]+)-([0-9]+)/$ show_birthday.php?day=$1&month=$2 [QSA,L]
RewriteRule ^birthyear-([0-9]+)/$ show_birthyear.php?year=$1 [QSA,L]
RewriteRule ^death-([0-9]+)-([0-9]+)/$ show_deathday.php?day=$1&month=$2 [QSA,L]
RewriteRule ^deathyear-([0-9]+)/$ show_deathyear.php?year=$1 [QSA,L]
RewriteRule ^job-([0-9]+)/page/([0-9]+)$ show_job.php?id=$1&page=$2 [QSA,L]
RewriteRule ^nationality-([0-9]+)/page/([0-9]+)$ show_nationality.php?id=$1&page=$2 [QSA,L]
RewriteRule ^borg-([0-9]+)/page/([0-9]+)$ show_borg.php?borg=$1&page=$2 [QSA,L]
RewriteRule ^birth-([0-9]+)-([0-9]+)/page/([0-9]+)$ show_birthday.php?day=$1&month=$2&page=$3 [QSA,L]
RewriteRule ^birthyear-([0-9]+)/page/([0-9]+)$ show_birthyear.php?year=$1&page=$2 [QSA,L]
RewriteRule ^death-([0-9]+)-([0-9]+)/page/([0-9]+)$ show_deathday.php?day=$1&month=$2&page=$3 [QSA,L]
RewriteRule ^deathyear-([0-9]+)/page/([0-9]+)$ show_deathyear.php?year=$1&page=$2 [QSA,L]
RewriteRule ^page/([0-9]+)$ index.php?page=$1 [QSA,L]
RewriteRule ^sitemap-([0-9]+).xml$ sitemap.php?page=$1
Place this rule in bio/.htaccess:
RewriteEngine On
RewriteBase /bio/
RewriteRule ^(\d+)/(.*)$ show_person.php?id=$1&url=$2 [QSA,L]

.htaccess URL rewrites to the wrong file

Im trying to change my urls from mywebsite.co/keyword to mywebsite.co/web/keyword i found a few ways to do this but it always causes problems with my other rewrites here is what i have so far only problem with it is it wont redirect mywebsite.co/keyword to mywebsite.co/web/keyword
Options +FollowSymlinks -MultiViews
RewriteEngine on
RewriteBase /
RewriteRule ^screenshot/ - [L]
# If requested resource exists as a file or directory, skip next two rules
RewriteCond %{DOCUMENT_ROOT}/$1 -f [OR]
RewriteCond %{DOCUMENT_ROOT}/$1 -d
RewriteRule (.*) - [S=2]
# when there is no space make an external redirection
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^info/([0-9a-zA-Z]+) /search/info/info.php?keyword=$1 [QSA,L]
RewriteRule ^web/([0-9a-zA-Z]+) /search/web/index.php?search=$1 [QSA,L]
RewriteRule ^videos/([0-9a-zA-Z]+) /search/video/video.php?keyword=$1 [QSA,L]
RewriteRule ^images/([0-9a-zA-Z]+) /search/images/image.php?keyword=$1 [QSA,L]
RewriteRule ^news/([0-9a-zA-Z]+) /search/news/news.php?keyword=$1 [QSA,L]
RewriteRule ^products/([0-9a-zA-Z]+) /search/products/product.php?keyword=$1 [QSA,L]
RewriteRule ^maps/([0-9a-zA-Z]+) /search/maps/maps.php?keyword=$1 [QSA,L]
RewriteRule ^space/([0-9a-zA-Z]+) /search/space/space.php?keyword=$1 [QSA,L]
RewriteRule ^web/ /search/web/index.php [QSA,L]
RewriteRule ^info/ /search/info/info.php [QSA,L]
RewriteRule ^videos/ /search/video/video.php [QSA,L]
RewriteRule ^images/ /search/images/image.php [QSA,L]
RewriteRule ^news/ /search/news/news.php [QSA,L]
RewriteRule ^products/ /search/products/product.php [QSA,L]
RewriteRule ^maps/ /search/maps/maps.php [QSA,L]
RewriteRule ^space/ /search/space/space.php [QSA,L]
Have it this way:
Options +FollowSymlinks -MultiViews
RewriteEngine on
RewriteBase /
RewriteRule ^screenshot/ - [L]
# If requested resource exists as a file or directory, skip next two rules
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^info/([0-9a-zA-Z]+)/?$ /search/info/info.php?keyword=$1 [QSA,L]
RewriteRule ^web/([0-9a-zA-Z]+)/?$ /search/web/index.php?search=$1 [QSA,L]
RewriteRule ^videos/([0-9a-zA-Z]+)/?$ /search/video/video.php?keyword=$1 [QSA,L]
RewriteRule ^images/([0-9a-zA-Z]+)/?$ /search/images/image.php?keyword=$1 [QSA,L]
RewriteRule ^news/([0-9a-zA-Z]+)/?$ /search/news/news.php?keyword=$1 [QSA,L]
RewriteRule ^products/([0-9a-zA-Z]+)/?$ /search/products/product.php?keyword=$1 [QSA,L]
RewriteRule ^maps/([0-9a-zA-Z]+)/?$ /search/maps/maps.php?keyword=$1 [QSA,L]
RewriteRule ^space/([0-9a-zA-Z]+) /search/space/space.php?keyword=$1 [QSA,L]
RewriteRule ^web/?$ /search/web/index.php [QSA,L]
RewriteRule ^info/?$ /search/info/info.php [QSA,L]
RewriteRule ^videos/?$ /search/video/video.php [QSA,L]
RewriteRule ^images/?$ /search/images/image.php [QSA,L]
RewriteRule ^news/?$ /search/news/news.php [QSA,L]
RewriteRule ^products/?$ /search/products/product.php [QSA,L]
RewriteRule ^maps/?$ /search/maps/maps.php [QSA,L]
RewriteRule ^space/?$ /search/space/space.php [QSA,L]

Make redirect from www to non-www and allow futher processing

I want to redirect site from www to non-www.
The main issue is that .htaccess file of CMS is very complicated.
Otherwise this instruction in the start of the .htaccess should have worked
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.ecotrans-spb.ru$ [NC]
RewriteRule ^(.*)$ http://ecotrans-spb.ru/$1 [R=301,L]
What flags should I set here instead of these to allow .htaccess process the URL further?
Generic CMS .htaccess
AddDefaultCharset UTF-8
ErrorDocument 404 /404
ErrorDocument 401 /password.php
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.ecotrans-spb.ru$ [NC]
RewriteRule ^(.*)$ http://ecotrans-spb.ru/$1 [R=301]
# Админка теперь по адресу /simpla
RewriteRule ^admin/?$ simpla [L]
# Каталог товаров
RewriteRule ^catalog/([^/]+)/?$ index.php?module=ProductsView&category=$1 [L,QSA]
RewriteRule ^catalog/([^/]+)/([^/]+)/?$ index.php?module=ProductsView&category=$1&brand=$2 [L,QSA]
RewriteRule ^products/([^/]+)/?$ index.php?module=ProductView&product_url=$1 [L,QSA]
RewriteRule ^products/?$ index.php?module=ProductsView [L,QSA]
RewriteRule ^brands/([^/]+)/?$ index.php?module=ProductsView&brand=$1 [L,QSA]
RewriteRule ^brands/([^/]+)/page_([^/]+)/?$ index.php?module=ProductsView&brand=$1&page=$2 [L,QSA]
# Поиск товаров
RewriteRule ^search/([^/]+)/?$ index.php?module=ProductsView&keyword=$1 [L,QSA]
RewriteRule ^search/?$ index.php?module=ProductsView [L,QSA]
# Блог
RewriteRule ^blog/([^/]+)/?$ index.php?module=BlogView&url=$1 [L,QSA]
RewriteRule ^blog/?$ index.php?module=BlogView [L,QSA]
# Корзина и заказы
RewriteRule ^cart/?$ index.php?module=CartView [L,QSA]
RewriteRule ^cart/([^/]+)/?$ index.php?module=CartView&add_variant=$1 [L,QSA]
RewriteRule ^cart/remove/([^/]+)/?$ index.php?module=CartView&delete_variant=$1 [L,QSA]
RewriteRule ^order/([^/]+)/?$ index.php?module=OrderView&url=$1 [L,QSA]
RewriteRule ^order/?$ index.php?module=OrderView [L,QSA]
# Для пользователей
RewriteRule ^user/login/?$ index.php?module=LoginView [L,QSA]
RewriteRule ^user/register/?$ index.php?module=RegisterView [L,QSA]
RewriteRule ^user/logout/?$ index.php?module=LoginView&action=logout [L,QSA]
RewriteRule ^user/password_remind/?$ index.php?module=LoginView&action=password_remind [L,QSA]
RewriteRule ^user/password_remind/([0-9a-z]+)/?$ index.php?module=LoginView&action=password_remind&code=$1 [L,QSA]
RewriteRule ^user/?$ index.php?module=UserView [L,QSA]
# Google sitemap
RewriteRule ^sitemap.xml?$ sitemap.php [L,QSA]
# XML
RewriteRule ^yandex.xml?$ yandex.php [L,QSA]
# feedback
RewriteRule ^contact/?$ index.php?module=FeedbackView [L,QSA]
#downloads
RewriteRule ^order/([^/]+)/([^/]+)/?$ index.php?module=OrderView&url=$1&file=$2 [L,QSA]
# Статические страницы
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/?$ index.php?module=PageView&page_url=$1 [L,QSA]
RewriteRule ^/?$ index.php?module=MainView&page_url= [L,QSA]
# Ресайз картинок на лету
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^files/products/(.+) resize/resize.php?file=$1&token=%{QUERY_STRING}
#RewriteCond %{THE_REQUEST} ^GET\ (.*)files/products/(.*)\?([A-z0-9]*)
#RewriteRule ^files/products/(.+) resize/resize.php?file=%2&token=%3 [L,NE]
Removing the L from the last line will allow it to continue.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.ecotrans-spb.ru$ [NC]
RewriteRule ^(.*)$ http://ecotrans-spb.ru/$1 [R=301]
[L] is a flag that, if this rule matches, then no other rule matching will be performed.

.htaccess rule redirect all pages except a few provided ones

I have the following .htaccess file.
ErrorDocument 404 /404.php
RewriteRule ^aanbiedinginformatie$ aanbiedinginformatie.php
RewriteRule ^algemenevoorwaarden$ algemenevoorwaarden.php
RewriteRule ^contact$ contact.php
RewriteRule ^disclaimer$ disclaimer.php
RewriteRule ^faq$ faq.php
RewriteRule ^index$ index.php
RewriteRule ^informatie$ informatie.php
RewriteRule ^inloggen-bedrijven$ inloggen-bedrijven.php
RewriteRule ^inloggen-consument$ inloggen-consument.php
RewriteRule ^nieuws$ nieuws.php
RewriteRule ^(.*)-nieuws$ bekijknieuws.php?id=$1
RewriteRule ^(.*)-(.*)-persbericht$ persbericht.php?id=$1&bedrijf=$2
RewriteRule ^persberichteninformatie$ persberichteninformatie.php
RewriteRule ^privacy$ privacy.php
RewriteRule ^registreren-bedrijven$ registreren-bedrijven.php
RewriteRule ^registreren-bedrijven-stap-2$ registreren-bedrijven-stap-2.php
RewriteRule ^registreren-bedrijven-stap-3$ registreren-bedrijven-stap-3.php
RewriteRule ^registreren-bedrijven-stap-4$ registreren-bedrijven-stap-4.php
RewriteRule ^registreren-bedrijven-stap-5$ registreren-bedrijven-stap-5.php
RewriteRule ^registreren-consument$ registreren-consument.php
RewriteRule ^vacatureinformatie$ vacatureinformatie.php
RewriteRule ^(.*)-vacatures$ vacatures.php?id=$1
RewriteRule ^zoeken-op-(.*)$ zoeken.php?query=$1
RewriteRule ^zoeken-in-(.*)$ zoeken.php?plaats=$1
RewriteRule ^zoeken-q-(.*)-in-(.*)$ zoeken.php?query=$1&plaats=$2
RewriteRule ^(.*)-vacatures-zoeken$ zoekenvac.php?query=$1
RewriteRule ^(.*)-in-(.*)-vacatures$ zoekenvac.php?query=$1&plaats=$2
RewriteRule ^vacatures-in-(.*)$ zoekenvac.php?plaats=$1
RewriteRule ^(.*)-aanbiedingen$ zoekenaan.php?query=$1
RewriteRule ^(.*)-aanbiedingen-in-(.*)$ zoekenaan.php?query=$1&plaats=$2
RewriteRule ^aanbiedingen-in-(.*)$ zoekenaan.php?plaats=$1
RewriteRule ^(.*)-persberichten$ zoekenpers.php?query=$1
RewriteRule ^persberichten-in-(.*)$ zoekenpers.php?plaats=$1
RewriteRule ^(.*)-persberichten-in-(.*)$ zoekenpers.php?query=$1&plaats=$2
RewriteRule ^bedrijven-in-(.*)$ zoeken.php?plaats=$1
RewriteRule ^control/consument$ control/consument.php
RewriteRule ^control/consument-mijngegevens$ control/consument-mijngegevens.php
RewriteRule ^control/consument-wachtwoord$ control/consument-wachtwoord.php
RewriteRule ^control/consument-cv$ control/consument-cv.php
RewriteRule ^control/consument-reacties$ control/consument-reacties.php
RewriteRule ^control/consument-reviews$ control/consument-reviews.php
RewriteRule ^control/logout$ control/logout.php
RewriteRule ^control/bedrijven$ control/bedrijven.php
RewriteRule ^control/bedrijven-aanbieding$ control/bedrijven-aanbieding.php
RewriteRule ^control/bedrijven-facturen$ control/bedrijven-facturen.php
RewriteRule ^control/bedrijven-fotos$ control/bedrijven-fotos.php
RewriteRule ^control/bedrijven-kortingscode$ control/bedrijven-kortingscode.php
RewriteRule ^control/bedrijven-kortingscode-bewerken-(.*)$ control/bedrijven- kortingscode-bewerken.php?id=$1
RewriteRule ^control/bedrijven-kortingscode-verwijderen-(.*)$ control/bedrijven- kortingscode-verwijderen.php?id=$1
RewriteRule ^control/bedrijven-wachtwoord$ control/bedrijven-wachtwoord.php
RewriteRule ^control/bedrijven-pakket$ control/bedrijven-pakket.php
RewriteRule ^control/bedrijven-persbericht$ control/bedrijven-persbericht.php
RewriteRule ^control/bedrijven-persbericht-bewerken-(.*)$ control/bedrijven- persbericht-bewerken.php?id=$1
RewriteRule ^control/bedrijven-persbericht-verwijderen-(.*)$ control/bedrijven- persbericht-verwijderen.php?id=$1
RewriteRule ^control/bedrijven-profiel$ control/bedrijven-profiel.php
RewriteRule ^control/bedrijven-vacatures$ control/bedrijven-vacatures.php
RewriteRule ^control/bedrijven-vacatures-bekijk-(.*)$ control/bedrijven-vacatures- bekijk.php?id=$1
RewriteRule ^control/bedrijven-vacatures-bewerken-(.*)$ control/bedrijven-vacatures- bewerken.php?id=$1
RewriteRule ^control/bedrijven-vacatures-verwijderen-(.*)$ control/bedrijven-vacatures-verwijderen.php?id=$1
RewriteRule ^control/logoutb$ control/logoutb.php
RewriteRule ^(.*)$ bedrijf.php?q=$1 [L]
RewriteRule ^id(.*)-(.*)$ bedrijf.php?id=$1
RewriteRule ^branche(.*)-(.*)$ zoekenbranche.php?id=$1
What I want, is that all URL's except the one provided above will redirect to bedrijf.php?q=$1. I tried excluding but that doesn't work.
So www.site.com/companyname will redirect to bedrijf.php?q=companyname, while www.site.com/contact will redirect to contact.php
How would I do this?
Rewrite rules loop. The entire set of rules keep getting re-applied to the URI until the URI stops changing. Your rule here:
RewriteRule ^(.*)$ bedrijf.php?q=$1 [L]
Has no conditions to prevent a previously rewritten URI from getting rewritten to bedrijf.php, since (.*) matches everything.
Try adding some conditions to it, like:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ bedrijf.php?q=$1 [L]
or
RewriteCond %{ENV:REDIRECT_STATUS} !200
RewriteRule ^(.*)$ bedrijf.php?q=$1 [L]

mod_rewrite config for /

I have the following .htaccess config
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
RewriteRule \.git - [F,L]
RewriteRule ^help help.php [L]
RewriteRule ^home home.php [L]
RewriteRule ^profile profile.php [L]
RewriteRule ^index index.php [L]
RewriteRule ^users/([0-9]+) profile.php?id=$1 [L]
RewriteRule ^([A-Za-z0-9-]+)?$ profile.php?u=$1 [L]
Now, whenever somebody visits the landing page, they get redirected using the last rule for profile.php?u=$1.
How do I change the configuration so that www.example.com and www.example.com/ are mapped to index.php and not profile.php?
Match the empty string or single slash just after the ^index rule:
RewriteRule ^help help.php [L]
RewriteRule ^home home.php [L]
RewriteRule ^profile profile.php [L]
RewriteRule ^index index.php [L]
# Match root request with optional slash
RewriteRule ^/?$ index.php [L]
I will suggest not to do it this way.
Instead, simply user this
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
This will send all your requests to index.php page, from there create a router.php and pass on the requests to that page, using php.
but in case you do, just add
RewriteRule ^/?$ index.php [L]
Like Michael suggested.
Here is a simple tool to test your rules, if you wish to
Apache RewriteRule tester

Resources