Having Some Error With Htaccess when i adding dot operator to it

Viewed 61

i have two files one is php handler.php file and second one is a htaccess that working fine without .(dot) but when we add dot to its just echo handler.php

book/handler.php exist in book dir

<?php
echo $_GET['bookid'];
?>

.htaccess

RewriteEngine On

# i added 2 line one for book/abc and secon for book/abc/

RewriteRule ^book/([a-z-A-Z-0-9-.]+)$ book/handler.php?bookid=$1 [L,R=301]


RewriteRule ^book/([a-z-A-Z-0-9-/]+)/ book/handler.php?bookid=$1 [L,R=301]

when i submit localhost/book/handler.php?bookid=somthing.php it return handler.php

check out this url for demo link when i add book/somthing or book/somthing.php it return handler.php

1 Answers

Could you please try following, based on your shown samples only.

RewriteEngine ON
RewriteCond %{REQUEST_URI} !/handler\.php [NC]
RewriteCond %{THE_REQUEST} /book/([^\s]*)\s+ [NC]
RewriteRule ^(.*)$ /book/handler.php?%1 [NE,NC,L]

Explanation:

  • RewriteEngine ON: Making RewriteEngine on here so that mod rewrite rules are enabled.
  • RewriteCond %{REQUEST_URI} !/handler\.php [NC]: To avoid looping here, so that once redirection happens it should get failed in this, while coming after successful redirection.
  • RewriteCond %{THE_REQUEST} /book/([^\s]*)\s+ [NC]: In default variable THE_REQUEST using regex to match string book saving everything into first backreference so that could be used later in redirection part.
  • RewriteRule ^(.*)$ /book/handler.php?%1 [NE,NC,L]: Performing actual redirection(internal one) by passing /book/handler.php with value of 1st backreference here. Using flags NE, NC and L make redirection smooth.
Related