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: .htaccess code doesnt work in httpd.conf
Author
Qmpeltaty



Joined: 06 Feb 2008
Posts: 182
Location: Poland

PostPosted: Tue 13 Jun '17 14:19    Post subject: .htaccess code doesnt work in httpd.conf Reply with quote

Hi

Today i was fighting with moving test site version to the production. Developer was preparing the mobile webpage in Angular which requires .htaccess to be placed in DocumetRoot directory :

Code:
DirectoryIndex index.html

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ([^/]+)/?(.*) /mobile/index.html


As i don't like .htaccess files i proposed to move this configuration to httpd.conf :

Code:
<Location /mobile>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ([^/]+)/?(.*) /mobile/index.html
</Location>

"DirectoryIndex index.html" line had been removed from Location block


After placing the .htaccess content to Location block it stopped working as expected. What is the reason ?
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7288
Location: Germany, Next to Hamburg

PostPosted: Tue 13 Jun '17 14:58    Post subject: Reply with quote

Location does not work inside .htaccess files see docs [1] for that.

You need a second rewrite rule with the condition of the mobile location.



Maybe you can use the If statement

Code:

<If "%{REQUEST_URI} =~ /mobile/">
    RewriteRule ([^/]+)/?(.*) /mobile/index.html
</If>


but why ? ([^/]+)/?(.*)
[2]



Why not ^/mobile/(.*)
[3]




[1] https://httpd.apache.org/docs/2.4/en/mod/core.html#location
[2] ttps://regexper.com/#(%5B%5E%2F%5D%2B)%5C%2F%3F(.*)
[3] https://regexper.com/#%5E%5C%2Fmobile%5C%2F(.*)
Back to top
Qmpeltaty



Joined: 06 Feb 2008
Posts: 182
Location: Poland

PostPosted: Tue 13 Jun '17 15:23    Post subject: Reply with quote

I didn't put the Location block to .htacces but opposite, .htaccess file's content to httpd.conf within Location block.
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7288
Location: Germany, Next to Hamburg

PostPosted: Tue 13 Jun '17 15:47    Post subject: Reply with quote

Then you might try RewriteBase[1]




Code:

<Location /mobile>
RewriteEngine On
RewriteBase /mobile
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ index.html [QSA,L]
</Location>




[1] http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritebase

Quote:
The RewriteBase directive specifies the URL prefix to be used for per-directory (htaccess) RewriteRule directives that substitute a relative path.
Back to top
Qmpeltaty



Joined: 06 Feb 2008
Posts: 182
Location: Poland

PostPosted: Tue 13 Jun '17 18:10    Post subject: Reply with quote

I tried RewriteBase as well but it didn't work either.
Back to top


Reply to topic   Topic: .htaccess code doesnt work in httpd.conf View previous topic :: View next topic
Post new topic   Forum Index -> Apache