Forum Moderators: phranque

Message Too Old, No Replies

Periods in RewriteRule give an Internal Server Error

         

jonfleck

2:13 pm on Feb 15, 2010 (gmt 0)

10+ Year Member



Here is my old rewrite rule.

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^([a-zA-Z0-9\-_]+)$ /index.php?name=$1 [L]
</IfModule>

The old rule works great but I wanted to add the ability for users to use have periods in the url. For example, in the following URLs periods seem to make the most sense:

en.opensuse.org/OpenSUSE_11.2

instead of en.opensuse.org/OpenSUSE_11_2

or

en.wikipedia.org/wiki/Mac_OS_X_v10.1

instead of en.wikipedia.org/wiki/Mac_OS_X_v10_1

As you can see, having periods in the URL makes for a more readable URL.

I added a period to the rule and now I receive an Internal Server Error.

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^([a-zA-Z0-9\-_.]+)$ /index.php?name=$1 [L]
</IfModule>

I've also tried escaping the period, but have also had no luck with that.

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^([a-zA-Z0-9\-_\.]+)$ /index.php?name=$1 [L]
</IfModule>

If somebody could please let me know what I'm doing wrong and how to correct the problem it would be greatly appreciated.

jdMorgan

6:40 pm on Feb 15, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You've created an infinite rewrite loop, since the output filepath will now match the rewriterule pattern.

Replace:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^([a-zA-Z0-9\-_.]+)$ /index.php?name=$1 [L]
</IfModule>

with

RewriteEngine On
#
RewriteCond $1 !^index\.php$
RewriteRule ^([a-z0-9_.\-]+)$ /index.php?name=$1 [NC,L]

All changes intentional.

Jim