Solved

RewriteRule with NOTHING on the end of URL

Posted on 2006-11-16
10
264 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
 
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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

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…
Introduction As you’re probably aware the HTTP protocol offers basic / weak authentication, which in combination with the relevant configuration on your web server, provides the ability to password protect all or part of your host.  If you were not…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

896 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