Reputation: 1625
I have a site that has mode rewrite. The problem is that when in the rewrited url there is a dot, it leads to 404. I tried from this post
RewriteCond %{REQUEST_URI} !=/index.php
RewriteRule ^(.*).(.*)$ /$1$2 [L,R=301]
RewriteRule ^page/cart/([^./]+)/?$ ./index.php?page=cart&$1 [L,PT]
RewriteRule ^page/([^.]+)?/([^.]+)?/([^.]+)?/([^.]+)?/([^.]+)?/?$ ./index.php?page=$1&catId=$2&subId=$3&id=$4&name=$5 [L,PT]
RewriteRule ^page/([^.]+)?/([^.]+)?/([^.]+)?/([^.]+)?/?$ ./index.php?page=$1&catId=$2&subId=$3&name=$4 [L,PT]
RewriteRule ^page/([^.]+)?/([^.]+)?/([^.]+)?/?$ ./index.php?page=$1&catId=$2&name=$3 [L,PT]
RewriteRule ^page/([^.]+)?/([^.]+)?/?$ ./index.php?page=$1&id=$2 [L,PT]
RewriteRule ^page/([^./]+)/?$ ./index.php?page=$1&name=$2 [L,PT]
RewriteRule ^page/([^./]+)/?$ ./index.php?page=$1 [L,PT]
But it still gives me 404's. My goal is when i have dot in the url, to permanently redirect to same url without dot.
How can i acheive this?
EDIT:
I edited my file with this combination to exclude all the images, but it seems first condition doesn't apply:
RewriteCond %{REQUEST_URI} !=/(.*)\.(jpg|gif|png|css|js)$ [NC]
RewriteCond %{REQUEST_URI} !=/index.php
RewriteRule ^(.*)\.(.*)$ /$1$2 [L,R=301]
RewriteRule ^page/cart/([^./]+)/?$ ./index.php?page=cart&$1 [L,PT]
RewriteRule ^page/([^.]+)?/([^.]+)?/([^.]+)?/([^.]+)?/([^.]+)?/?$ ./index.php?page=$1&catId=$2&subId=$3&id=$4&name=$5 [L,PT]
RewriteRule ^page/([^.]+)?/([^.]+)?/([^.]+)?/([^.]+)?/?$ ./index.php?page=$1&catId=$2&subId=$3&name=$4 [L,PT]
RewriteRule ^page/([^.]+)?/([^.]+)?/([^.]+)?/?$ ./index.php?page=$1&catId=$2&name=$3 [L,PT]
RewriteRule ^page/([^.]+)?/([^.]+)?/?$ ./index.php?page=$1&id=$2 [L,PT]
RewriteRule ^page/([^./]+)/?$ ./index.php?page=$1&name=$2 [L,PT]
RewriteRule ^page/([^./]+)/?$ ./index.php?page=$1 [L,PT]
EDIT 2:
I found my mistake.
First row should be RewriteCond %{REQUEST_URI} !\.(jpg|gif|png|css|js)$ [NC]
instead RewriteCond %{REQUEST_URI} !=(.*)\.(jpg|gif|png|css|js)$ [NC]
Thanks.
Upvotes: 1
Views: 1151
Reputation: 143906
You need to escape the .
:
RewriteRule ^(.*)\.(.*)$ /$1$2 [L,R=301]
The .
character is reserved in regex to mean "any character that isn't a newline".
Upvotes: 2