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
Related
RewriteEngine On
<IfModule mod_rewrite.c>
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\.elancemart\.com [NC]
RewriteRule (.*) https://elancemart.com/$1 [L,R=301]
</IfModule>
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php
RewriteRule ^services/([a-zA-Z0-9-]+) service_details.php?slug=$1 [NC,L]
RewriteRule ^category/([a-zA-Z-]+) category.php?catSlug=$1 [NC,L]
RewriteRule ^blog/([0-9]+)/([a-zA-Z0-9-]+) blog/article.php?id=$1&&slug=$2 [NC,L]
RewriteRule ^verify/([a-zA-Z0-9-]+) verify.php?verify=$1 [NC,L]
RewriteRule ^services services.php
RewriteRule ^services/page/([\d])$ /services.php?page=$1 [NC,L,QSA]
RewriteRule ^funds add-funds.php [NC,L]
RewriteRule ^sitemap\.xml/?$ sitemap.php
RewriteRule ^article-sitemap\.xml/?$ article-sitemap.php
ErrorDocument 404 /index.php
I am getting 404 error when hitting services/page/([\d+])$ /services.php?page=$1
The file exists, though When I change the rewrite rule to service/page/([\d+])$ it is working fine, I need services in the URL, not service.
With your shown samples, please try following htaccess rules in your htaccess file. I have put 3 of services rules one after another to make it easy looking.
Also make sure your htaccess file is present along side with servcies.php file.
Please make sure to clear your browser cache before testing your URLs.
RewriteEngine On
<IfModule mod_rewrite.c>
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\.elancemart\.com [NC]
RewriteRule ^(.*)/?$ https://elancemart.com/$1 [L,R=301]
</IfModule>
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)/?$ $1.php [L]
RewriteRule ^services/(\w+)/?$ service_details.php?slug=$1 [NC,L]
RewriteRule ^services/?$ services.php [NC,L]
RewriteRule ^services/page/(\d+)/?$ services.php?page=$1 [NC,L,QSA]
RewriteRule ^category/([a-zA-Z-]+)/?$ category.php?catSlug=$1 [NC,L]
RewriteRule ^blog/([0-9]+)/(\w+)/?$ blog/article.php?id=$1&&slug=$2 [NC,L]
RewriteRule ^verify/(\w+)/?$ verify.php?verify=$1 [NC,L]
RewriteRule ^funds/?$ add-funds.php [NC,L]
RewriteRule ^sitemap.xml/?$ sitemap.php [NC,L]
RewriteRule ^article-sitemap.xml/?$ article-sitemap.php [NC,L]
ErrorDocument 404 /index.php
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?
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]
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.
So here's my code:
RewriteEngine On
RewriteRule ^contact$ contact.php [QSA,L]
RewriteRule ^error$ error.php [QSA,L]
RewriteRule ^([^/.]+)/?$ product.php?weblink=$1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . /error [L,R=301]
It's simple so when I try to access host/product-name it works but when I try to access for example a directory /blog or /blog/ redirect pe to error page specified by last rule. What's the problem?
You can do it this way
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule . - [L]
RewriteRule ^contact$ contact.php [QSA,L]
RewriteRule ^error$ error.php [QSA,L]
RewriteRule ^([^/.]+)/?$ product.php?weblink=$1 [L,QSA]
RewriteRule . /error [L,R=301]