Author |
|
donna9
Joined: 24 Sep 2016 Posts: 6 Location: Toronto
|
Posted: Sat 24 Sep '16 17:11 Post subject: Question about RewriteCond |
|
|
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
|
Posted: Sat 24 Sep '16 19:40 Post subject: |
|
|
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
|
Posted: Sat 24 Sep '16 19:57 Post subject: |
|
|
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 |
|
Back to top |
|
spser
Joined: 29 Aug 2016 Posts: 97
|
Posted: Sat 24 Sep '16 21:26 Post subject: |
|
|
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
|
Posted: Sat 24 Sep '16 22:55 Post subject: |
|
|
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
|
Posted: Sun 25 Sep '16 0:09 Post subject: |
|
|
Thank you! Very much appreciated! |
|
Back to top |
|