Solved

RewriteRule with NOTHING on the end of URL

Posted on 2006-11-16
10
263 Views
Last Modified: 2010-03-04
Hello,

I would like:

         http://www.mysite.com/foobar

to be re-written as:

         http://www.mysite.com/index.php?page=foobar


This works ONLY if zz is at the end:

         RewriteRule ^(.*)zz index.php?page=$1 [NE]

This does NOT work:

         RewriteRule ^(.*) index.php?page=$1 [NE]

Any ideas?
Thanks!
0
Comment
Question by:hankknight
10 Comments
 
LVL 15

Expert Comment

by:periwinkle
Comment Utility
Try:

RewriteRule ^(.*)$ index.php?page=$1 [NE]
0
 
LVL 43

Assisted Solution

by:ravenpl
ravenpl earned 250 total points
Comment Utility
There's propably a typo, but You need leading slash on second param for RewriteRule and loop detection
RewriteCond %{REQUEST_URI} !^index.php
RewriteRule ^(.*)$ /index.php?page=$1 [NE,L]

Also if used in httpd.conf instead of .htaccess
RewriteCond %{REQUEST_URI} !^/index.php
RewriteRule ^/(.*)$ /index.php?page=$1 [NE,L]

You sure You want NE (no-escape) flag? Refer http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html#rewriterule
0
 
LVL 16

Author Comment

by:hankknight
Comment Utility
Thanks.

Neither of these work:

         RewriteRule ^(.*)$ index.php?page=$1 [NE]
            or
         RewriteRule ^(.*)$ index.php?page=$1 [NE,L]

They both seem to redirect to:    
         index.php?page=index.php
 regardless of what the url is.

Also, thanks ravenpl for pointing out the NE and loop detection issues.





0
 
LVL 27

Accepted Solution

by:
caterham_www earned 250 total points
Comment Utility
There is nothing not to escape in your subsitution's filename index.php - you won't need the NE-flag here.

RewriteCond $1 !=index.php
RewriteRule ^(.*)$ index.php?page=$1 [L]

should stop the bahaviour. If your requests doesn't contain any periods, the regEx ^([^.]+)$  would be more efficient. You won't need the condition in that case, too.
0
 
LVL 41

Expert Comment

by:HonorGod
Comment Utility
Where do you have the directives?  In your httpd.conf file, or in you .htaccess file?
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 43

Expert Comment

by:ravenpl
Comment Utility
hankknight: You haven't use my advice, have You? Not that I added one more line, and modified the original...
0
 
LVL 13

Expert Comment

by:rhickmott
Comment Utility
If your making your pages search engine freindly then the best way is to fool them into thinking the page is not dynamic (PHP Driven) by giving it a HTM extension so that it thinks it is a static HTMl page.

Options +FollowSymLinks
RewriteEngine On
RewriteRule ^(.*)\.htm$ index.php?page=$1 [L]

For example

http://www.mydomain.com/foobar.htm

will call the PHP script index.php?page=foobar and the URL will still appear as if they are looking at foobar.htm.
0
 
LVL 16

Author Comment

by:hankknight
Comment Utility
Thanks,

This seems to work best for me.

            RewriteEngine on
            RewriteCond $1 !=admin/
            RewriteRule ^([^.]+)$ index.php?page=$1 [L]

I have posted a related question here:
http://www.experts-exchange.com/Web/Web_Servers/Apache/Q_22064358.html
0
 
LVL 43

Expert Comment

by:ravenpl
Comment Utility
I don't understand why it's working for You, but whatever...
0
 
LVL 16

Author Comment

by:hankknight
Comment Utility
->> I don't understand why it's working for you

Thanks for asking.

     RewriteCond %{REQUEST_URI} !^/index.php
     RewriteRule ^/(.*)$ /index.php?page=$1 [NE,L

This does NOT prevent things like:
     info.php
from being re-written.

But this:
     RewriteRule ^([^.]+)$ index.php?page=$1 [L]
does not re-write ANYTHING that has a . in it.

That is why.
   
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

In my time as an SEO for the last 2 years and in the questions I have assisted with on here I have always seen the need to redirect from non-www urls to their www versions. For instance redirecting http://domain.com (http://domain.com) to http…
Hi, in this article I'm going to teach you how to run your own site, and how to let people in (without IP). I'll talk about and explain each step... :) By the way, everything in this Tutorial is completely free and legal. This article is for …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

743 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now