Solved

RewriteRule with NOTHING on the end of URL

Posted on 2006-11-16
10
270 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 15

Expert Comment

by:periwinkle
ID: 17958884
Try:

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

Assisted Solution

by:ravenpl
ravenpl earned 250 total points
ID: 17959301
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
ID: 17960192
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
Independent Software Vendors: 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!

 
LVL 27

Accepted Solution

by:
caterham_www earned 250 total points
ID: 17960769
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
ID: 17962430
Where do you have the directives?  In your httpd.conf file, or in you .htaccess file?
0
 
LVL 43

Expert Comment

by:ravenpl
ID: 17963328
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
ID: 17964013
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
ID: 17964727
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
ID: 17964926
I don't understand why it's working for You, but whatever...
0
 
LVL 16

Author Comment

by:hankknight
ID: 17965688
->> 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

If your site has a few sections that need to be secure when data is transmitted between the server and local computer, such as a /order/ section for ordering or /customer/ which contains customer data, etc it would of course be recommended to secure…
If you are a web developer, you would be aware of the <iframe> tag in HTML. The <iframe> stands for inline frame and is used to embed another document within the current HTML document. The embedded document could be even another website.
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Suggested Courses

617 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