u01jmg3 Posted November 15, 2007 Share Posted November 15, 2007 Hi, just wondered if anyone could help me out with this small .htaccess problem and using mod_rewrite? Basically I already have a working .htaccess file but I wondered if there was a way of writing a generic rule for what I have rather than writing a rule for every page of my site in my .htaccess. Here's what I mean... ---------------------------------------------------- (1.) Here's the current rule for a page on my site: RewriteRule ^corporate_training$ 14_corporate_training.php (2.) And here's the current rule for a particular section of a page: RewriteRule ^corporate_training/anger_management$ 14_corporate_training.php?course=anger_management Could this be made generic with one single rule for each? ---------------------------------------------------- Also if someone uses a trailing slash for any page of my site such as: http://www.realize-scotland.co.uk/corporate.htm/ it gives an error - is there anyway of properly interpreting this in the same way: http://www.realize-scotland.co.uk/corporate.htm is properly understood? ---------------------------------------------------- Thanks. Jonathan. Quote Link to comment Share on other sites More sharing options...
michaellunsford Posted November 19, 2007 Share Posted November 19, 2007 Yes. RewriteRule ^corporate_training/([a-zA-Z0-9_]+)/?$ 14_corporate_training.php?course=$1 [L,NS] the /? makes the trailing slash optional. Quote Link to comment Share on other sites More sharing options...
u01jmg3 Posted November 20, 2007 Author Share Posted November 20, 2007 Thanks very much for your reply michaellunsford. This is what's now in my .htaccess file but can it be shrunk further??? RewriteEngine on #---------------------------------------------- #Home - Corporate Training - Site 1 #---------------------------------------------- RewriteRule ^home-corporate_training/?$ 11_home.php #---------------------------------------------- #About Us #---------------------------------------------- RewriteRule ^about_us/?$ 12_about_us.php RewriteRule ^about_us/([a-zA-Z0-9_]+)/?$ 12_about_us.php?skill=$1 [L,NS] #---------------------------------------------- #Corporate Training #---------------------------------------------- RewriteRule ^corporate_training/?$ 14_corporate_training.php RewriteRule ^corporate_training/([a-zA-Z0-9_]+)/?$ 14_corporate_training.php?course=$1 [L,NS] #---------------------------------------------- Quote Link to comment Share on other sites More sharing options...
michaellunsford Posted November 20, 2007 Share Posted November 20, 2007 You could try to make the whole back part optional RewriteRule ^about_us(/([a-zA-Z0-9_]+))?/?$ 12_about_us.php?skill=$1 [L,NS] I haven't tested it, though. Quote Link to comment Share on other sites More sharing options...
u01jmg3 Posted November 21, 2007 Author Share Posted November 21, 2007 Thanks very much for your help. Worked like a charm! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.