Page 3 of 3

Re: Period . sends page to 404, but only on some URLs..

Posted: Tue Nov 08, 2016 9:00 am
by simonmlewis
I've modified it a little, to reduce duplication of rules where there are pages.

Code: Select all

DirectoryIndex index.php index.html index.htm
order allow,deny
allow from all 
Options +FollowSymLinks
Options +Indexes
RewriteEngine On
ErrorDocument 404 /custom_404.php
# RewriteCond %{HTTPS} !=on
# RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# Remove multiple slashes after domain
RewriteCond %{HTTP_HOST} !=""
RewriteCond %{THE_REQUEST} ^[A-Z]+\s//+(.*)\sHTTP/[0-9.]+$ [OR]
RewriteCond %{THE_REQUEST} ^[A-Z]+\s(.*/)/+\sHTTP/[0-9.]+$
RewriteRule .* http://%{HTTP_HOST}/%1 [R=301,L]

# Remove multiple slashes anywhere in URL
RewriteCond %{REQUEST_URI} ^(.*)//(.*)$
RewriteRule . %1/%2 [R=301,L]


RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]

RewriteRule ^(blog)($|/) - [QSA]
RewriteRule product-tags/bb-pellet$ /categ/bb-pellets? [R=301,L]


# old url rewrite
RewriteRule ^categ/([0-9]+)/([^/]+)$ /index.php?page=categ&c=$1&cname=$2 [L]
RewriteRule ^categ/page/([0-9]+)/([^/]+)/([0-9]+)$ /index.php?page=categ&c=$1&cname=$2&pagenum=$3 [L]
RewriteRule ^subcateg/([0-9]+)/([^/]+)/([0-9]+)/([^/]+) /index.php?page=subcateg&c=$1&cname=$2&s=$3&sname=$4&menu=sub [L]
RewriteRule ^subcateg/page/([0-9]+)/([^/]+)/([0-9]+)/([^/]+)/([0-9]+) /index.php?page=subcateg&c=$1&cname=$2&s=$3&sname=$4&pagenum=$5 [L]

RewriteRule ^product/([0-9]+)/([^/]+)/([0-9]+)/([^/]+)/([0-9]+)/([^/]+)$ /index.php?page=product&c=$1&cname=$2&s=$3&sname=$4&product=$5&h=$6 [L]
# end of old url rewrite


# NEW URLS
RewriteRule ^categ/([^/]+)/([0-9]+)$ /index.php?page=categ&cname=$1&pagenum=$2 [L] 
RewriteRule ^categ/([^/]+)$ /index.php?page=categ&cname=$1 [L]

RewriteRule ^subcateg/([^/]+)/([^/]+)/([0-9]+)$ /index.php?page=subcateg&cname=$1&sname=$2&pagenum=$3 [L]
RewriteRule ^subcateg/([^/]+)/([^/]+)$ /index.php?page=subcateg&cname=$1&sname=$2 [L]

RewriteRule ^product/([^/]+)/([^/]+)/([0-9]+)/([^/]+)$ /index.php?page=product&cname=$1&sname=$2&product=$3&h=$4 [L]
# END OF NEW URLS

RewriteRule ^knowledge/([0-9]+) /index.php?page=knowledge&id=$1 [QSA]
RewriteRule ^knowledge/answer/([0-9]+)/([0-9]+) /index.php?page=knowledge&id=$1&id_link=$2 [QSA]

RewriteRule ^([^/]+)/page/([0-9]+) /index.php?page=$1&pagenum=$2 [QSA]

RewriteRule ^loadout/([0-9]+)/([^/]+)/([0-9]+)/([^/]+)/([0-9]+)/([^/]+) /index.php?page=loadout&c=$1&cname=$2&s=$3&sname=$4&product=$5&h=$6 [QSA]
RewriteRule ^pricematch/([0-9]+) /index.php?page=pricematch&id=$1 [QSA]

RewriteRule ^type/([^/]+) /index.php?page=type&type=$1 [QSA]
RewriteRule ^use/([^/]+)/([0-9]+)$ /index.php?page=use&use=$1&pagenum=$2 [QSA]
RewriteRule ^use/([^/]+) /index.php?page=use&use=$1 [QSA]

RewriteRule ^back-in-stock/page/([0-9]+)/([^/]+) /index.php?page=back-in-stock&pagenum=$1&power=$2 [L,QSA]

RewriteRule ^romancode/([^/]+) /index.php?page=romancode&romancode=$1 [QSA]
RewriteRule ^productsall/([0-9]+) /index.php?page=productsall/ [QSA]
RewriteRule ^pricesearch/([0-9]+) /index.php?page=pricesearch&pagenum=$1/ [QSA]

RewriteRule ^productsall/page/([0-9]+) /index.php?page=productsall&pagenum=$1/ [QSA]
RewriteRule ^productsairsoft/page/([0-9]+) /index.php?page=productsairsoft&pagenum=$1/ [QSA]
RewriteRule ^manufacturers/([^/]+) /index.php?page=manufacturers&manufacturer=$1 [QSA]
RewriteRule ^accessories-manufacturers/([^/]+) /index.php?page=accessories-manufacturers&manufacturer=$1 [QSA]
RewriteRule ^other-manufacturers/([^/]+) /index.php?page=other-manufacturers&manufacturer=$1 [QSA]

RewriteRule ^videos/([0-9]+) /index.php?page=videos&catid=$1 [QSA]
RewriteRule ^videos/product/([0-9]+)/([0-9]+) /index.php?page=videos&catid=$1&id=$2 [QSA]
RewriteRule ^videos/product-search/([0-9]+)/([0-9]+)/([^/]+)/([^/]+) /index.php?page=videos&catid=$1&id=$2&search=$3&searchvideo=$4 [QSA]

RewriteRule ^whatcustomerssay/([0-9]+) /index.php?page=whatcustomerssay&pagenum=$1/ [QSA]

RewriteRule ^([^/\.]+)/?$ index.php?page=$1 [L]
RewriteRule ^all-products /index.php?page=all-products [QSA]

RewriteRule ^$ index.php?page=home [QSA]

Re: Period . sends page to 404, but only on some URLs..

Posted: Tue Nov 08, 2016 9:12 am
by Celauran
Huh. This does it.
[text]RewriteRule ^all-products(.*) /index.php?page=all-products$1 [L,QSA][/text]

https://httpd.apache.org/docs/current/r ... l#flag_qsa

Documentation suggests that capture group shouldn't be required, but it appears it is.

Re: Period . sends page to 404, but only on some URLs..

Posted: Tue Nov 08, 2016 9:30 am
by Celauran
Unless there's a reason for excluding the full stop, this may be a better approach:

[text]RewriteRule ^([^/]+)/?$ index.php?page=$1 [QSA,L][/text]

Re: Period . sends page to 404, but only on some URLs..

Posted: Tue Nov 08, 2016 9:30 am
by simonmlewis
First one worked!I don't really understand the difference tho.

Re: Period . sends page to 404, but only on some URLs..

Posted: Tue Nov 08, 2016 9:31 am
by Celauran
First what and the difference between what?

Re: Period . sends page to 404, but only on some URLs..

Posted: Tue Nov 08, 2016 9:43 am
by simonmlewis
Why did this not work:
RewriteRule ^([^/]+)/?$ index.php?page=$1 [QSA,L]

But this did:
RewriteRule ^all-airguns(.*) /index.php?page=all-airguns$1 [L,QSA]

Re: Period . sends page to 404, but only on some URLs..

Posted: Tue Nov 08, 2016 9:47 am
by Celauran
[text]RewriteRule ^([^/]+)/?$ index.php?page=$1 [QSA,L][/text]
Is working as expected for me.

Re: Period . sends page to 404, but only on some URLs..

Posted: Tue Nov 08, 2016 9:54 am
by Celauran
Looking through that file, I have also noticed that you're sending every request to index.php. Seems to me it would be a lot simpler to cut your htaccess logic to a single rule and handle the routing in the code.