RewriteRule issues

New to mod_rewrite? This is a good place to start.

RewriteRule issues

Postby ylight51 » Fri Sep 11, 2009 7:50 pm

Hey all,

I'm a bit of an htaccess n00b, and can't for the life of me get a handle of regular expressions.

I have the following piece of Rewrite Rule code that works just fine:

RewriteRule ^logo/?$ /pages/logo.html

Basically, it takes domain.com/pages/logo.html and makes it domain.com/logo.

Is there a way for me to generalize that code with variables, so that it works automatically without having to have an independent line for each page?
ylight51
 
Posts: 1
Joined: Fri Sep 11, 2009 7:46 pm

Postby richardk » Sat Sep 12, 2009 3:00 pm

logo is the only part that changes, right?

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

# Make sure /pages/logo.html exists.
RewriteCond %{DOCUMENT_ROOT}/pages/$1.html -f
RewriteRule ^([^/]+)/?$ /pages/$1.html [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Beginner's Corner

Who is online

Users browsing this forum: No registered users and 8 guests

cron