Search code examples
php.htaccessmod-rewriteamp-html

PHP Multiple Mod Rewrite Rule For AMP


I'am having trouble with below php rewrite mode code, someone coded that website in past, everything is complicated. All cms goes from index.php?goto string.

Now I want to have amp pages something like,

/amp/blog.amp.php?catidx=how-to-fix-misshapen-teeth

/amp/blog/topic.html, I tried with this code but didnt work.

RewriteCond %{REQUEST_URI} "^(.+)/amp/blog.amp.php?catidx=$"
RewriteCond "%{DOCUMENT_ROOT}/amp/blog/$1.html"  -f
RewriteRule "^(.+)/amp/blog/$" "%{DOCUMENT_ROOT}/amp/blog.amp.php?catidx=$1"  [L]

* Existing Htaccess Code *

Options +FollowSymLinks


RewriteEngine on
ReWriteRule ^([a-z\-]+)/([a-z\-0-9]+)/([a-z\-0-9]+)/([a-z\-0-9]+)$  index.php?goto=$1&catidx=$2&cat_idx=$3&cat_idx2=$4 [L,NC]

ReWriteRule ^([a-z\-]+)/([a-z\-0-9]+)/([a-z\-0-9]+)$    index.php?goto=$1&catidx=$2&cat_idx=$3 [L,NC]

ReWriteRule ^([a-z\-]+)/([a-z\-0-9]+)$  index.php?goto=$1&catidx=$2 [L,NC]

ReWriteRule ^([a-z\-0-9]+)$ index.php?goto=$1&mailsuccess=$2 [L,NC]

RewriteCond %{THE_REQUEST} /index\.(php|html?) [NC]

RewriteRule ^(.*)index\.(?:php|html?)$ /$1 [L,R=302,NC,NE]
[L,NC]

I will be really happy if you could help me.


Solution

  • I deleted these because they were overwriting everything.

    ReWriteRule ^([a-z\-]+)/([a-z\-0-9]+)/([a-z\-0-9]+)/([a-z\-0-9]+)$  index.php?goto=$1&catidx=$2&cat_idx=$3&cat_idx2=$4 [L,NC]
    
    ReWriteRule ^([a-z\-]+)/([a-z\-0-9]+)/([a-z\-0-9]+)$    index.php?goto=$1&catidx=$2&cat_idx=$3 [L,NC]
    

    And added this code; everything works like a charm.

    ReWriteRule ^amp/blog/([a-z\-0-9]+).amp.html$   amp/blog.amp.php?catidx=$1 [L,NC]