Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

In main page index.php I have two href (like menu) for objective.php and news.php
For both objectives and news I sent variables like:

<a href="objectives.php?menu=corporate-objectives">  
<a href="news.php?article=meetings">  

The idea is to load content for each page separately and to change the url's to symbolic links like:

/MyTest_proj/corporate-objectives  
/MyTest_proj/meetings  

I've tried in many ways to rewrite rules in htaccess especially to rewriterule for both pages but most of time work only for the first rewriterule for example:

RewriteRule ^([-a-zA-Z0-9]+)?$ objectives.php?menu=$1  
RewriteRule ^([-a-zA-Z0-9]+)?$ news.php?article=$1  

which obviously both page match the same paterns and the meetings was loaded in objectives.php otherwise (or in other case) I got the 401 error... The question is how do I must put and to write these rewriterules and conditions if there is any to work for both pages ?

share|improve this question
    
I've managed to put the write rules (I think) and it worked, here is the code: "RewriteRule ^home(.*)$ index.php" "RewriteRule ^news/([-a-zA]+)/?$ news.php?article=$1" "RewriteRule ^objectives/([-a-zA-Z]+)/?$ objectives.php?menu=$1" I suppose it wasn't work before because I've used the same patterns Also I've changed the href's to display simbolic url's in address bar "<a href="objectives/corporate-objectives">" "<a href="news/meeting-news">" wich is also worked BUT STILL, I'm not sure if I did the right thing so please I need advice or ok confirmation Thanks ! –  Virgil Raica Feb 27 '13 at 8:56

1 Answer 1

The problem is that your RewriteRule matches any URL containing alphanumerical strings, thus matching both "corporate-objectives" and "news". Since mod_rewrite will apply the first matching rule, it never makes it to the second.

In other words, you need to make your RewriteRules more specific. Here's an example that should get you started:

RewriteRule ^([-a-zA-Z0-9]*objectives)?$ objectives.php?menu=$1  
RewriteRule ^([-a-zA-Z0-9]+)?$ news.php?article=$1  

This should mean that any URL containing the word "objectives" will load objectives.php, and anything else will load news.php.

share|improve this answer
    
I've managed to put the write rules (I think) and it worked, here is the code: RewriteRule ^home(.*)$ index.php RewriteRule ^news/([-a-zA]+)/?$ news.php?article=$1 RewriteRule ^objectives/([-a-zA-Z]+)/?$ objectives.php?menu=$1 I suppose it wasn't work before because I've used the same patterns Also I've changed the href's to display simbolic url's in address bar <a href="objectives/corporate-objectives"> <a href="news/meeting-news"> wich is also worked BUT STILL, I'm not sure if I did the right thing so please I need advice or ok confirmation Thanks! –  Virgil Raica Feb 27 '13 at 9:09
    
The way to know if you did it right is to try it with a variety of URLs and see if it does what you want it to. Only you can say if it works or not! –  Jenny D Feb 27 '13 at 9:12

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.