Htaccess Using RewriteMap with a text file

Htaccess Using RewriteMap with a text file - .htaccess files are extremely useful in many cases for users who either do not have root permissions or for users who simply aren't comfortable in making changes in their web server's configuration file. Trying to debug .htaccess not working isn't always the easiest thing to do, however, hopefully by checking the discuss below mentioned about htaccess, mod-rewrite, , , .htaccess common problems as well as the troubleshooting tips, you'll have a better grasp on what you may have to modify to get your .htaccess file running smoothly.Problem :


I can't use link with *
Example - http://localhost/photo_gallery/public/show_c.html/color-1* The requested URL was not found on this server.
The others work's color-3, wood, etc.



  1. generated map - map.txt


    title   id
    color-1* 1
    color-1** 2
    color-3 3
    wood 4
    color777 5
    color-test 6


  2. htaccess


    RewriteRule ^show_c.html/([-w]+)$ show_c.php?cat=$catcolors:$1 [L]


  3. httpd.conf


    RewriteMap catcolors "txt:C:wampwwwphoto_gallerypublicmapsmap.txt"



My question. Why the link with * cannot be used.


Solution :


RewriteRule ^show_c.html/([-w]+)$ show_c.php?cat=$catcolors:$1 [L]


The regex [-w]+ does not match *, so the pattern never matches the requested URL-path and the value is never looked up in the rewrite map.


Try the following instead:


RewriteRule ^show_c.html/([-*w]+)$ show_c.php?cat=$catcolors:$1 [L]

The literal * does not need to be backslash escaped in the regex character class as it carries no special meaning here. (But remember to backslash escape literal dots in other parts of the regex.)


Specifically, the regex [-*w]+ matches 1 or more of the following:

- (hyphen), * (asterisk), a-z, A-Z, 0-9 and _ (underscore)


Additionally, if you would like to do some further testing, give the htaccess tester tool a try. It allows you to specify a certain URL as well as the rules you would like to include and then shows which rules were tested, which ones met the criteria, and which ones were executed.

Comments

Popular posts from this blog

Rewrite in Mediawiki, remove index.php, .htaccess

.htaccess rewrite wildcard folder paths from host

Using .htaccess to set a cookie and 301 redirect