?
Solved

RewriteRule problem adding extension

Posted on 2007-08-02
4
Medium Priority
?
233 Views
Last Modified: 2013-12-12
I currently have the following .htaccess file that mod.rewrites a query to something resembling a static URL:

Options +FollowSymLinks

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase   /about/campus/
RewriteRule ^([^.]+)$ profile.php?country=$1
</IfModule>

This allows for campus information about Canada to appear as /about/campus/canada, but I'd like to add the PHP extension to the back of the URL. When I place .php in the RewriteRule, however, it doesn't work unless I add [QSA] to the end, but then all PHP files in that direct redirect to profile.php.

I am a novice at mod.rewrite, any help is appreciated.
0
Comment
Question by:matthutaff
  • 2
  • 2
4 Comments
 
LVL 4

Expert Comment

by:jentulman
ID: 19619411
This should do it

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase   /about/campus/
RewriteRule ^([^.]+)\.php$ profile.php?country=$1
</IfModule>
0
 

Author Comment

by:matthutaff
ID: 19619463
It should (I've tried that solution), but when I use that RewriteRule, it passes "profile" as the query string.
0
 
LVL 4

Accepted Solution

by:
jentulman earned 2000 total points
ID: 19620617
Sorry yeah,

Try going back to your original rule, add the [QSA] again and then add these two lines like this,

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteBase   /about/campus/
RewriteRule ^([^.]+)\.php$ profile.php?country=$1
</IfModule>

if the requested file doesn't exist and isn't a directory then apply the rule. Should allow the other php files in the directory to ba called without a problem.
0
 

Author Comment

by:matthutaff
ID: 19620662
Ding ding ding! Works great!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It is possible to boost certain documents at query time in Solr. Query time boosting can be a powerful resource for finding the most relevant and "best" content. Of course the more information you index, the more fields you will be able to use for y…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses
Course of the Month16 days, 17 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question