# Please convert this mod rewrite rule

**URL:** <https://www.ruby-forum.com/t/please-convert-this-mod-rewrite-rule/205638>\
**Category:** NGINX\
**Created:** [April 12, 2011, 12:15am UTC](https://www.ruby-forum.com/t/please-convert-this-mod-rewrite-rule/205638 "2011-04-12T00:15:58Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [April 12, 2011, 12:15am UTC](https://www.ruby-forum.com/t/please-convert-this-mod-rewrite-rule/205638/1 "2011-04-12T00:15:58Z")

</div>

Hi,

# Tell PHP that the mod\_rewrite module is ENABLED.

SetEnv HTTP\_MOD\_REWRITE On  
Options +FollowSymLinks  
RewriteEngine on  
RewriteRule test-(._).htm$ inc/tesmodrewite.php?q=test\_$1  
RewriteRule test2-(._).htm$ /inc/tesmodrewite.php?q=test\_$1  
RewriteRule pm-(._).(jpg|png|gif|html)$ index.php?pm=$1  
RewriteRule pt-(._).(jpg|png|gif|html)$ index.php?pt=$1  
RewriteRule dt-(._).(jpg|png|gif)$ index.php?dt=$1  
RewriteRule dm-(._).(jpg|png|gif)$ index.php?dm=$1  
RewriteRule di-(._).(jpg|jpeg|png|gif|bmp)$ index.php?di=$1  
RewriteRule page(._).html$ gallery.php?p=$1

Thanks

Thanks

Posted at Nginx Forum:

> **[Please convert this mod rewrite rule](https://forum.nginx.org/read.php?2,190338,190338#msg-190338)**
>
> Hi, \<IfModule mod\_rewrite.c\> # Tell PHP that the mod\_rewrite module is ENABLED. SetEnv HTTP\_MOD\_REWRITE On Options +FollowSymLinks RewriteEngine on RewriteRule test-(.\*)\\.htm$ inc/tesmodrewite.php?q=test\_$1 RewriteRule test

---

<div class="post-metadata">

**Author:** ![alex1950](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ecae2f/32.png) [@alex1950](https://www.ruby-forum.com/u/alex1950)\
**Post date:** [April 12, 2011, 12:51am UTC](https://www.ruby-forum.com/t/please-convert-this-mod-rewrite-rule/205638/2 "2011-04-12T00:51:04Z")

</div>

On Mon, Apr 11, 2011 at 06:15:09PM -0400, alex1950 wrote:

Hi there,

> RewriteRule test-(._).htm$ inc/tesmodrewite.php?q=test\_$1  
> RewriteRule test2-(._).htm$ /inc/tesmodrewite.php?q=test\_$1  
> RewriteRule pm-(.\*).(jpg|png|gif|html)$ index.php?pm=$1

As some starting notes:

- replace “RewriteRule” with “rewrite”
- stick a “;” at the end of the line
- the first character of the request is “/”
- the replacement probably wants to start with “/”
- debug log is your friend

The third note is relevant if your regex starts with “^”. None of yours  
here do.

For the fourth note, do you want “/a/b/test-c.htm”  
to be rewritten to “/inc/tesmodrewite.php?q=test\_c” or to  
“/a/b/inc/tesmodrewite.php?q=test\_c”? (The answer is probably obvious  
to one who knows the apache syntax well.) You’ll want the leading “/”  
either explicitly, or as part of a (new) initial (.\*) in the regex and  
corresponding $1 in the replacement.

Good luck with it,

## f

Francis D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![alex1950](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ecae2f/32.png) [@alex1950](https://www.ruby-forum.com/u/alex1950)\
**Post date:** [April 12, 2011, 1:56am UTC](https://www.ruby-forum.com/t/please-convert-this-mod-rewrite-rule/205638/3 "2011-04-12T01:56:38Z")

</div>

rewrite /test-(._).htm$ /inc/tesmodrewite.php?q=test\_$1;  
rewrite /test2-(._).htm$ /inc/tesmodrewite.php?q=test\_$1;  
rewrite /pm-(._).(jpg|png|gif|html)$ /index.php?pm=$1;  
rewrite /pt-(._).(jpg|png|gif|html)$ /index.php?pt=$1;  
rewrite /dt-(._).(jpg|png|gif)$ /index.php?dt=$1;  
rewrite /dm-(._).(jpg|png|gif)$ /index.php?dm=$1;  
rewrite /di-(._).(jpg|jpeg|png|gif|bmp)$ /index.php?di=$1;  
rewrite /page(._).html$ /gallery.php?p=$1;

i added this in my htaccess file but not working ! ☹

- debug log is your friend ( how can i Create or Access to that ? )

Note : I’m Root Access !

Posted at Nginx Forum:

> **[Re: Please convert this mod rewrite rule](https://forum.nginx.org/read.php?2,190338,190358#msg-190358)**
>
> Hi, \<IfModule mod\_rewrite.c\> # Tell PHP that the mod\_rewrite module is ENABLED. SetEnv HTTP\_MOD\_REWRITE On Options +FollowSymLinks RewriteEngine on RewriteRule test-(.\*)\\.htm$ inc/tesmodrewite.php?q=test\_$1 RewriteRule test

---

<div class="post-metadata">

**Author:** ![alex1950](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ecae2f/32.png) [@alex1950](https://www.ruby-forum.com/u/alex1950)\
**Post date:** [April 12, 2011, 7:49am UTC](https://www.ruby-forum.com/t/please-convert-this-mod-rewrite-rule/205638/4 "2011-04-12T07:49:12Z")

</div>

Nginx does not support .htaccess files. You need to add the rewrite  
rules to the server configuration and reload nginx.

alex1950 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) schrieb:

rewrite /test-(._).htm$ /inc/tesmodrewite.php?q=test\_$1; rewrite  
/test2-(._).htm$ /inc/tesmodrewite.php?q=test\_$1; rewrite  
/pm-(._).(jpg|png|gif|html)$ /index.php?pm=$1; rewrite  
/pt-(._).(jpg|png|gif|html)$ /index.php?pt=$1; rewrite  
/dt-(._).(jpg|png|gif)$ /index.php?dt=$1; rewrite  
/dm-(._).(jpg|png|gif)$ /index.php?dm=$1; rewrite  
/di-(._).(jpg|jpeg|png|gif|bmp)$ /index.php?di=$1; rewrite  
/page(._).html$ /gallery.php?p=$1; i added this in my htaccess file but  
not working ! ☹ \* debug log is your friend ( how can i Create or Access  
to that ? ) Note : I’m Root Access ! Posted at Nginx Forum:

> **[Re: Please convert this mod rewrite rule](https://forum.nginx.org/read.php?2,190338,190358#msg-190358 _____________________________________________ )**
>
> Hi, \<IfModule mod\_rewrite.c\> # Tell PHP that the mod\_rewrite module is ENABLED. SetEnv HTTP\_MOD\_REWRITE On Options +FollowSymLinks RewriteEngine on RewriteRule test-(.\*)\\.htm$ inc/tesmodrewite.php?q=test\_$1 RewriteRule test

nginx mailing list removed\_email\_address@domain.invalid  
[http://nginx.org/mailman/listinfo/nginx](http://nginx.org/mailman/listinfo/nginx)

---

<div class="post-metadata">

**Author:** ![alex1950](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ecae2f/32.png) [@alex1950](https://www.ruby-forum.com/u/alex1950)\
**Post date:** [April 12, 2011, 8:20am UTC](https://www.ruby-forum.com/t/please-convert-this-mod-rewrite-rule/205638/5 "2011-04-12T08:20:02Z")

</div>

On Mon, Apr 11, 2011 at 06:15:09PM -0400, alex1950 wrote:

> RewriteRule pm-(._).(jpg|png|gif|html)$ index.php?pm=$1  
> RewriteRule pt-(._).(jpg|png|gif|html)$ index.php?pt=$1  
> RewriteRule dt-(._).(jpg|png|gif)$ index.php?dt=$1  
> RewriteRule dm-(._).(jpg|png|gif)$ index.php?dm=$1  
> RewriteRule di-(._).(jpg|jpeg|png|gif|bmp)$ index.php?di=$1  
> RewriteRule page(._).html$ gallery.php?p=$1

If you want to use configuraiton which will be easy to maintain in  
future,  
do not use rewrite’s:

```
location /test- {
     location ~ ^/test-(.+)\.htm$ {
         fastcgi_pass ...
         fastcgi_param SCRIPT_FILENAME 

```

/path/to/inc/tesmodrewite.php;  
fastcgi\_param QUERY\_STRING q=test\_$1;  
…  
}  
}

```
location /test2- {
     location ~ ^/test2-(.+)\.htm$ {
         fastcgi_pass ...
         fastcgi_param SCRIPT_FILENAME 

```

/path/to/inc/tesmodrewite.php;  
fastcgi\_param QUERY\_STRING q=test\_$1;  
…  
}  
}

Yes, the configuration will be larger, but every location is independent  
and may be changed or new locations may be added without worry how it  
will affect other parts of the configuration.

–  
Igor S.
