htaccess - Redirecting php files - .htaccess

I am writing my .htaccess file for my website. It contains 30+ php files that have act as front-end for the courses.
I have tried the code below but whenever you access my website: www.conuplugs.com, it redirects to COMP248 for some reason
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ class/comp232.php?path=$1 [NC,L,QSA]
RewriteRule ^(.*)$ class/comp248.php?path=$1 [NC,L,QSA]
RewriteRule ^(.*)$ class/engr201.php?path=$1 [NC,L,QSA]
RewriteRule ^(.*)$ class/engr213.php?path=$1 [NC,L,QSA]
RewriteRule ^(.*)$ class/comp249.php?path=$1 [NC,L,QSA]
RewriteRule ^(.*)$ class/soen228.php?path=$1 [NC,L,QSA]
RewriteRule ^(.*)$ class/soen287.php?path=$1 [NC,L,QSA]
RewriteRule ^(.*)$ class/engr233.php?path=$1 [NC,L,QSA]
RewriteRule ^(.*)$ class/comp348.php?path=$1 [NC,L,QSA]
RewriteRule ^(.*)$ class/comp352.php?path=$1 [NC,L,QSA]
RewriteRule ^(.*)$ class/encs282.php?path=$1 [NC,L,QSA]
RewriteRule ^(.*)$ class/engr202.php?path=$1 [NC,L,QSA]
RewriteRule ^(.*)$ class/comp346.php?path=$1 [NC,L,QSA]
RewriteRule ^(.*)$ class/soen331.php?path=$1 [NC,L,QSA]
RewriteRule ^(.*)$ class/soen341.php?path=$1 [NC,L,QSA]
RewriteRule ^(.*)$ class/engr371.php?path=$1 [NC,L,QSA]
RewriteRule ^(.*)$ class/elec275.php?path=$1 [NC,L,QSA]
RewriteRule ^(.*)$ class/comp335.php?path=$1 [NC,L,QSA]
RewriteRule ^(.*)$ class/soen342.php?path=$1 [NC,L,QSA]
RewriteRule ^(.*)$ class/soen343.php?path=$1 [NC,L,QSA]
RewriteRule ^(.*)$ class/soen344.php?path=$1 [NC,L,QSA]
RewriteRule ^(.*)$ class/soen345.php?path=$1 [NC,L,QSA]
RewriteRule ^(.*)$ class/soen384.php?path=$1 [NC,L,QSA]
RewriteRule ^(.*)$ class/engr391.php?path=$1 [NC,L,QSA]
RewriteRule ^(.*)$ class/soen357.php?path=$1 [NC,L,QSA]
RewriteRule ^(.*)$ class/soen390.php?path=$1 [NC,L,QSA]
RewriteRule ^(.*)$ class/engr301.php?path=$1 [NC,L,QSA]
RewriteRule ^(.*)$ class/soen321.php?path=$1 [NC,L,QSA]
RewriteRule ^(.*)$ class/soen490.php?path=$1 [NC,L,QSA]
RewriteRule ^(.*)$ class/engr392.php?path=$1 [NC,L,QSA]
RewriteRule ^(.*)$ class/soen385.php?path=$1 [NC,L,QSA]
RewriteRule ^(.*)$ class/comp354.php?path=$1 [NC,L,QSA]
As mentioned earlier, this redirects to COMP248.php, how can I fix this?

Related

my hosting error 500 if use .htaccess

my hosting error 500 if use .htaccess
this my .htaccess file
RewriteEngine On
AllowOverride All
RewriteBase /
RewriteCond %{HTTPS} off
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [L,R=301]
RewriteRule ^developer.html$ developer.php [QSA,L]
RewriteRule ^multishrink.html$ multishrink.php [QSA,L]
RewriteRule ^stats.html$ public-stats.php [QSA,L]
RewriteRule ^feed.rss feed.php [QSA,L]
RewriteRule ^([^/]+)\.qrcode$ qrcode.php?id=$1 [QSA,L]
RewriteRule ^api.php$ API/simple.php [QSA,L]
RewriteRule ^API/write/(get|post)$ API/write.php?method=$1 [QSA,L]
RewriteRule ^API/read/(get|post)$ API/read.php?method=$1 [QSA,L]
RewriteRule ^([^/]+)/stats$ stats.php?id=$1 [QSA,L]
RewriteRule ^([^/]+)/unlock$ unlock.php?id=$1 [QSA,L]
RewriteRule ^privacy.html$ privacy.php [QSA,L]
RewriteRule ^disclaimer.html$ disclaimer.php [QSA,L]
RewriteRule ^contact.html$ contact.php [QSA,L]
# If path is not a directory or file then apply RewriteRule
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^([0-9a-zA-Z-]{1,60})$ go.php?id=$1 [QSA,L]Options -Indexes
how to fix this

all pages are loading except index page?

I've a htaccess code here.All the pages will work with redirect except the home page. I made changes in conf file also but no use please help. It says object not found when I click the home page link.
DirectoryIndex index.php
RewriteEngine on
AddDefaultCharset UTF-8
RewriteCond %{HTTP} =on
RewriteRule ^home/?$ index.php [NC,L,QSA]
RewriteRule ^about-us/?$ about.php [NC,L,QSA]
RewriteRule ^quick-service/?$ quick_service.php [NC,L,QSA]
RewriteRule ^road-side/?$ road_side.php [NC,L,QSA]
RewriteRule ^video-visualization/?$ video_visual.php [NC,L,QSA]
RewriteRule ^distance-approach/?$ distance_approach.php [NC,L,QSA]
RewriteRule ^pickup-drop/?$ pickup_drop.php [NC,L,QSA]
RewriteRule ^checking-status/?$ checking_status.php [NC,L,QSA]
RewriteRule ^genuine-parts/?$ genuine_parts.php [NC,L,QSA]
RewriteRule ^book-vehicle/?$ book_vehicle.php [NC,L,QSA]
RewriteRule ^Sign-In/?$ login.php [NC,L,QSA]
RewriteRule ^Register/?$ register.php [NC,L,QSA]
RewriteRule ^purchase-parts/?$ purchase.php [NC,L,QSA]
RewriteRule ^contact/?$ contact.php [NC,L,QSA]
RewriteRule ^service-centers/?$ service_centers.php [NC,L,QSA]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php

.htaccess redirect not found page to a specific page

Here's my code
RewriteRule ^error$ error.php [QSA,L]
RewriteRule ^siteuri_partenere$ siteuri_partenere.php [QSA,L]
RewriteRule ^politica_de_confidentialitate$ politica_de_confidentialitate.php [QSA,L]
RewriteRule ^blog - [L,NC]
RewriteRule ^([^/.]+)/?$ game.php?weblink=$1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . /error [L,R=302]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
So, if i change this line
RewriteRule . /error [L,R=302]
to
RewriteRule . /page_not_found [L,R=302]
and then i test www.domain.com/1q2w3e, is still redirect to /error and not to /page_not_found so i'm very confusing where is the problem?
Most likely you have some ErrorDocument 404 directive that is overriding your rewrite rules. Place this code in your root .htaccess:
Options +FollowSymLinks -MultiViews
ErrorDocument 404 default
RewriteEngine On
RewriteRule ^blog - [L,NC]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteRule ^error$ error.php [L]
RewriteRule ^siteuri_partenere$ siteuri_partenere.php [L]
RewriteRule ^politica_de_confidentialitate$ politica_de_confidentialitate.php [L]
RewriteRule ^([^/.]+?)/?$ game.php?weblink=$1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /page_not_found [L,R=302]

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.

Where to add www redirect code in a existing bbpress htaccess file?

I recently installed bbpress on a domain of mine. and it came with a .htaccess file which looks like this ->
# BEGIN bbPress
Options -MultiViews
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^page/([0-9]+)/?$ /index.php?page=$1 [L,QSA]
RewriteRule ^forum/([^/]+)/page/([0-9]+)/?$ /forum.php?id=$1&page=$2 [L,QSA]
RewriteRule ^forum/([^/]+)/?$ /forum.php?id=$1 [L,QSA]
RewriteRule ^forum/?$ / [R=302,L,QSA]
RewriteRule ^topic/([^/]+)/page/([0-9]+)/?$ /topic.php?id=$1&page=$2 [L,QSA]
RewriteRule ^topic/([^/]+)/?$ /topic.php?id=$1 [L,QSA]
RewriteRule ^topic/?$ / [R=302,L,QSA]
RewriteRule ^tags/([^/]+)/page/([0-9]+)/?$ /tags.php?tag=$1&page=$2 [L,QSA]
RewriteRule ^tags/([^/]+)/?$ /tags.php?tag=$1 [L,QSA]
RewriteRule ^tags/?$ /tags.php [L,QSA]
RewriteRule ^profile/([^/]+)/page/([0-9]+)/?$ /profile.php?id=$1&page=$2 [L,QSA]
RewriteRule ^profile/([^/]+)/([^/]+)/?$ /profile.php?id=$1&tab=$2 [L,QSA]
RewriteRule ^profile/([^/]+)/([^/]+)/page/([0-9]+)/?$ /profile.php?id=$1&tab=$2&page=$3 [L,QSA]
RewriteRule ^profile/([^/]+)/?$ /profile.php?id=$1 [L,QSA]
RewriteRule ^profile/?$ /profile.php [L,QSA]
RewriteRule ^view/([^/]+)/page/([0-9]+)/?$ /view.php?view=$1&page=$2 [L,QSA]
RewriteRule ^view/([^/]+)/?$ /view.php?view=$1 [L,QSA]
RewriteRule ^rss/?$ /rss.php [L,QSA]
RewriteRule ^rss/topics/?$ /rss.php?topics=1 [L,QSA]
RewriteRule ^rss/forum/([^/]+)/?$ /rss.php?forum=$1 [L,QSA]
RewriteRule ^rss/forum/([^/]+)/topics/?$ /rss.php?forum=$1&topics=1 [L,QSA]
RewriteRule ^rss/topic/([^/]+)/?$ /rss.php?topic=$1 [L,QSA]
RewriteRule ^rss/tags/([^/]+)/?$ /rss.php?tag=$1 [L,QSA]
RewriteRule ^rss/tags/([^/]+)/topics/?$ /rss.php?tag=$1&topics=1 [L,QSA]
RewriteRule ^rss/profile/([^/]+)/?$ /rss.php?profile=$1 [L,QSA]
RewriteRule ^rss/view/([^/]+)/?$ /rss.php?view=$1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ /index.php [L]
</IfModule>
# END bbPress
Now I want to add a non-www to www redirect code in it, which is ->
RewriteCond %{HTTP_HOST} ^example\.com$
RewriteRule ^(.*) http://www.example.com/$1 [R=301]
Where should I put it? I found here that I should put it right after RewriteEngine On but doing so makes the UI break. CSS file locations break.
So where should I put it?
Here is the final .htaccess file that's working -
# BEGIN bbPress
Options -MultiViews
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^example\.com$
RewriteRule ^(.*) http://www.example.com/$1 [L,QSA]
RewriteRule ^page/([0-9]+)/?$ /index.php?page=$1 [L,QSA]
RewriteRule ^forum/([^/]+)/page/([0-9]+)/?$ /forum.php?id=$1&page=$2 [L,QSA]
RewriteRule ^forum/([^/]+)/?$ /forum.php?id=$1 [L,QSA]
RewriteRule ^forum/?$ / [R=302,L,QSA]
RewriteRule ^topic/([^/]+)/page/([0-9]+)/?$ /topic.php?id=$1&page=$2 [L,QSA]
RewriteRule ^topic/([^/]+)/?$ /topic.php?id=$1 [L,QSA]
RewriteRule ^topic/?$ / [R=302,L,QSA]
RewriteRule ^tags/([^/]+)/page/([0-9]+)/?$ /tags.php?tag=$1&page=$2 [L,QSA]
RewriteRule ^tags/([^/]+)/?$ /tags.php?tag=$1 [L,QSA]
RewriteRule ^tags/?$ /tags.php [L,QSA]
RewriteRule ^profile/([^/]+)/page/([0-9]+)/?$ /profile.php?id=$1&page=$2 [L,QSA]
RewriteRule ^profile/([^/]+)/([^/]+)/?$ /profile.php?id=$1&tab=$2 [L,QSA]
RewriteRule ^profile/([^/]+)/([^/]+)/page/([0-9]+)/?$ /profile.php?id=$1&tab=$2&page=$3 [L,QSA]
RewriteRule ^profile/([^/]+)/?$ /profile.php?id=$1 [L,QSA]
RewriteRule ^profile/?$ /profile.php [L,QSA]
RewriteRule ^view/([^/]+)/page/([0-9]+)/?$ /view.php?view=$1&page=$2 [L,QSA]
RewriteRule ^view/([^/]+)/?$ /view.php?view=$1 [L,QSA]
RewriteRule ^rss/?$ /rss.php [L,QSA]
RewriteRule ^rss/topics/?$ /rss.php?topics=1 [L,QSA]
RewriteRule ^rss/forum/([^/]+)/?$ /rss.php?forum=$1 [L,QSA]
RewriteRule ^rss/forum/([^/]+)/topics/?$ /rss.php?forum=$1&topics=1 [L,QSA]
RewriteRule ^rss/topic/([^/]+)/?$ /rss.php?topic=$1 [L,QSA]
RewriteRule ^rss/tags/([^/]+)/?$ /rss.php?tag=$1 [L,QSA]
RewriteRule ^rss/tags/([^/]+)/topics/?$ /rss.php?tag=$1&topics=1 [L,QSA]
RewriteRule ^rss/profile/([^/]+)/?$ /rss.php?profile=$1 [L,QSA]
RewriteRule ^rss/view/([^/]+)/?$ /rss.php?view=$1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ /index.php [L]
</IfModule>
# END bbPress
Changing the [R=301] part to [L,QSA] solved the 301 error part..

Resources