logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Apache View previous topic :: View next topic
Reply to topic   Topic: Need some help with Apache RewriteRule in .htaccess
Author
tykesplace



Joined: 16 Nov 2013
Posts: 3

PostPosted: Sat 16 Nov '13 9:18    Post subject: Need some help with Apache RewriteRule in .htaccess Reply with quote

Hello,

I'm new to Apache and am just learning and researching Rewrite. I've been reading Apache tutorials and have a very basic understanding of the RewriteRule syntax. For my current site I'm trying rewrite URLs if the requested URL contains a particular sub folder.

Example:
Code:
http://mysite.com/static/readme.html
is the clean url I'd like to use. That URL should load the page located at
Code:
http://mysite.com/local/staticpage/view.php?page=readme


/mysite.com/httpdocs/static/ is the folder that contains static pages that the /local/staticpage/view.php plugin inserts into my application. Here's what the plugin's developer suggested to put in my .htaccess


Code:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^/static/(.*)\.html$ /local/staticpage/view.php?page=$1&%{QUERY_STRING} [L]


I also tried:
Code:
RewriteRule ^(.*)/static/(.*)\.html$ $1/local/staticpage/view.php?page=$2&%{QUERY_STRING} [L]

and
Code:
RewriteRule ^(.*)/static/(.*)\.html$ $1/local/staticpage/view.php?page=$2 [L]


On my site the .php url is valid. But the clean url returns 404.

I can understand the RewriteRule syntax I'm using, except for the &%{QUERY_STRING}

Any ideas? Thanks in advance. Let me know if I need to provide any more information.
Darrel
Back to top
Steffen
Moderator


Joined: 15 Oct 2005
Posts: 3058
Location: Hilversum, NL, EU

PostPosted: Sun 17 Nov '13 12:41    Post subject: Reply with quote

You can try to include a rule inside <directory> :


<Directory "x:/xxx/xxx/static">

Rule

</Directory>
Back to top
tykesplace



Joined: 16 Nov 2013
Posts: 3

PostPosted: Tue 19 Nov '13 18:01    Post subject: Reply with quote

Thanks for the response Steffan. Please understand that I'm very new to Apache. I don't quite understand what your saying about <directory>.

I tried this but received an internal server error.

Options +FollowSymLinks
RewriteEngine On
<Directory "http://mysite.com/static">
RewriteRule ^/static/(.*)\.html$ /local/staticpage/view.php?page=$1&%{QUERY_STRING} [L]
</Directory>

Was that what you were suggesting I try?

Darrel
Back to top
Steffen
Moderator


Joined: 15 Oct 2005
Posts: 3058
Location: Hilversum, NL, EU

PostPosted: Tue 19 Nov '13 20:14    Post subject: Reply with quote

Explanation <directory> is at http://httpd.apache.org/docs/2.4/mod/core.html#directory .

You cannot use http://.. with directory, but the path to the folder where you want to apply the rule. For example c:/apache2/xx/xx
Back to top
tykesplace



Joined: 16 Nov 2013
Posts: 3

PostPosted: Wed 20 Nov '13 17:48    Post subject: Reply with quote

Whilst trying various things I discovered that I needed to remove the leading slash before static/ in the RewriteRule.


Options +FollowSymLinks
RewriteEngine On
RewriteRule ^static/(.*)\.html$ /local/staticpage/view.php?page=$1&%{QUERY_STRING} [L]

or

RewriteRule ^(.*)static/(.*)\.html$ $1/local/staticpage/view.php?page=$2 [L]


Either of those work.

Thanks for your assistance.
Back to top


Reply to topic   Topic: Need some help with Apache RewriteRule in .htaccess View previous topic :: View next topic
Post new topic   Forum Index -> Apache