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: Question about RewriteCond
Author
donna9



Joined: 24 Sep 2016
Posts: 6
Location: Toronto

PostPosted: Sat 24 Sep '16 17:11    Post subject: Question about RewriteCond Reply with quote

I'm trying to write a rule set where if the file exists and is named: _index.html or _index.xml or _index.rss or _index.atom or _index.rdf then serve up that specific file. I assumed it would be something like this:
Code:
RewriteCond %{REQUEST_URI} \/$
RewriteCond "/_index.(html|xml|rss|atom|rdf)" -f
RewriteRule .* "/_index.%1" [L]

My problem is that it seems RewriteCond does not allow regex for its first parameter. I believe it only allows a static string or environment variables. So whee i have (html|xml|rss|atom|rdf) wont work on the line because apache interprets it as part of the file name instead of a regex "or" divider.

How do i fix this?

Thank you.


Last edited by donna9 on Sat 24 Sep '16 19:58; edited 1 time in total
Back to top
spser



Joined: 29 Aug 2016
Posts: 97

PostPosted: Sat 24 Sep '16 19:40    Post subject: Reply with quote

RewriteCond %{REQUEST_URI} "_index\.(html|xml|rss|atom|rdf)"
RewriteRule (.*) "index.%1" [L]

is done.
Back to top
donna9



Joined: 24 Sep 2016
Posts: 6
Location: Toronto

PostPosted: Sat 24 Sep '16 19:57    Post subject: Reply with quote

Hi @spser..oh sorry, i should point out that the request is always in the form of http://mydomain.com/page/ ...and so when that style of request comes in then i want to do a check if a file with a certain extension exists on disk...and if one is found then return that back to the request.

so...

1. the user calls with http://mydomain.com/page/
2. htaccess checks the disk for an existence of _index.html or _index.rss or _index.rdf or _index.atom
3. If such a file is found then return that back

So your response will not work Sad
Back to top
spser



Joined: 29 Aug 2016
Posts: 97

PostPosted: Sat 24 Sep '16 21:26    Post subject: Reply with quote

RewriteBase /page/

RewriteCond %{REQUEST_URI} "_index\.(html|xml|rss|atom|rdf)"
RewriteRule (.*) "test.%1" [QSA]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) "test.php?file=noneexists" [L]
Back to top
spser



Joined: 29 Aug 2016
Posts: 97

PostPosted: Sat 24 Sep '16 22:55    Post subject: Reply with quote

RewriteCond %{DOCUMENT_ROOT}/wordpress/test.%1 -f
RewriteRule (.*) "test.%1" [QSA]

exists file
Back to top
donna9



Joined: 24 Sep 2016
Posts: 6
Location: Toronto

PostPosted: Sun 25 Sep '16 0:09    Post subject: Reply with quote

Thank you! Very much appreciated!
Back to top


Reply to topic   Topic: Question about RewriteCond View previous topic :: View next topic
Post new topic   Forum Index -> Apache