Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

RewriteRule with NOTHING on the end of URL

Posted on 2006-11-16
10
Medium Priority
?
273 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 1000 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
Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

 
LVL 27

Accepted Solution

by:
caterham_www earned 1000 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

[Webinar] Cloud Security

In this webinar you will learn:

-Why existing firewall and DMZ architectures are not suited for securing cloud applications
-How to make your enterprise “Cloud Ready”, and fix your aging DMZ architecture
-How to transform your enterprise and become a Cloud Enabler

Question has a verified solution.

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

As Wikipedia explains 'robots.txt' as -- the robot exclusion standard, also known as the Robots Exclusion Protocol or robots.txt protocol, is a convention to prevent cooperating web spiders and other web robots from accessing all or part of a websit…
If you've heard about htaccess and it sounds like it does what you want, but you're not sure how it works... well, you're in the right place. Read on. Some Basics #1. It's a file and its filename is .htaccess (yes, with a dot in the front). #…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses
Course of the Month13 days, 9 hours left to enroll

963 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