Author |
|
tykesplace
Joined: 16 Nov 2013 Posts: 3
|
Posted: Sat 16 Nov '13 9:18 Post subject: Need some help with Apache RewriteRule in .htaccess |
|
|
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: 3093 Location: Hilversum, NL, EU
|
Posted: Sun 17 Nov '13 12:41 Post subject: |
|
|
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
|
Posted: Tue 19 Nov '13 18:01 Post subject: |
|
|
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: 3093 Location: Hilversum, NL, EU
|
|
Back to top |
|
tykesplace
Joined: 16 Nov 2013 Posts: 3
|
Posted: Wed 20 Nov '13 17:48 Post subject: |
|
|
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 |
|