Solved

RewriteRule with NOTHING on the end of URL

Posted on 2006-11-16
10
265 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
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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

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 …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

770 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