I have a URL Structure as mysite.com/category.php?c=abc&page=4
I need to have a URL Structure as mysite.com/category/abc/page/4
My Htaccess File code for this rewrite looks like this.
RewriteEngine On
<IfModule mod_rewrite.c>
https redirect Rule Here
</IfModule>
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php
RewriteRule ^([-w]+)$ blog-post.php?slug=$1 [NC,L]
RewriteRule ^amp/([-w]+)$ amp/amp.php?slug=$1 [NC,L]
RewriteRule ^mirror/([-w]+)$ mirror/post.php?slug=$1 [NC,L]
RewriteRule ^category/([a-zA-Z-]+) category.php?c=$1 [NC,L]
RewriteRule ^category/([a-zA-Z-/]+)/page/([0-9]+) category.php?c=$1&page=$2 [NC,L]
RewriteRule ^mirror/category/([a-zA-Z-]+) mirror/category.php?c=$1 [NC,L]
RewriteRule ^feed/([a-zA-Z-]+)$ feed/feed.php?f=$1 [NC,L]
RewriteRule ^author/([a-zA-Z0-9-]+) author.php?name=$1 [NC,L]
RewriteRule ^tag/([a-zA-Z0-9-]+) tag.php?t=$1 [NC,L]
RewriteRule ^mirror/tag/([a-zA-Z0-9-]+) mirror/tag.php?t=$1 [NC,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [R=301,L]
RewriteRule ^sitemap.xml/?$ sitemap.php
RewriteRule ^news-sitemap.xml/?$ news-sitemap.php
RewriteRule ^image-sitemap.xml/?$ image-sitemap.php
RewriteRule ^author-sitemap.xml/?$ author-sitemap.php
ErrorDocument 404 /404.php
ErrorDocument 500 Error
Options -Indexes
The problem I am facing is when I try to get the page number using the $_get[]
variable, I am not able to fetch it. Rest I am able to get the ABC through $_get[]
2
Answers
With your shown samples, please try following. Please make sure to clear your browser cache before testing your URLs.
There are 2 important points you need to take care. 1st- You didn’t use
$
anchor which makes sure your 1st rule matching only URI likehttp://locahost:80/category/testtest
so what’s happening your rules are matching both the URIs. 2nd- Is you need to add conditions to make sure these rules are applied to only non existing stuff(in ideal scenario).You have big set of rules. Let me make an attempt to get you going:
Make sure to test it after clearing your browser cache completely or test it from command line
curl
.