Forum Moderators: phranque

Message Too Old, No Replies

Need Mod Rewrite Help

         

pwamarketing

4:03 pm on Mar 5, 2010 (gmt 0)

10+ Year Member



have a domain called;

xyz.com (fake name)

and that website a some mod_rewrite directives in the .htaccess to strip out the .php extension. So if I have a file called test.php the url would be;

[xyz.com...]

The code to do that resides in the .htaccess file. The code is below;

# remove .php; use THE_REQUEST to prevent infinite loops
RewriteCond %{THE_REQUEST} ^GET\ (.*)\.php\ HTTP
RewriteRule (.*)\.php$ $1 [R=301]


# remove index
RewriteRule (.*)/index$ $1/ [R=301]

# remove slash if not directory
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} /$
RewriteRule (.*)/ $1 [R=301]

# add .php to access file, but don't redirect
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule (.*) $1\.php [L]

And this works great..

Now I want to add the ability to add the following type of URL.

The displayed url would be;

[xyz.com...]

The non rewritten string is;

[xyz.com...]

I tried this rule but it just get server 500 error.

RewriteRule ^article/([^/]*)\.htm$ /articles.php?article=$1 [L]

But this generates an error 500.

Any help with this would be appreciated.

Thanks,

Jeff

jdMorgan

6:06 am on Mar 7, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I don't see anything wrong with that new rule. What's in your server error log file?

You may have put this rule in the wrong spot... That could cause a 500-Server Error.

Jim

g1smd

7:56 am on Mar 7, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You'll need an [L] flag on every rule, and the redirects should really contain the protocol and domain name to redirect to, not just the new path.

The two step index.php => index => / redirection is messy. Put the index rule first, and fix the index.php => / change in one redirect. Modify the code to fix index.php directly to /.