2

I have centos 7 and I need to put this .htaccess file inside one of my directories (www/html/forum) in order to display friendly URLs so instead of looking like example.com/index.php?user=222 it would look like example.com/user/222.

<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule \.(jpeg|jpg|gif|png)$ /public/404.php [NC,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

This worked fine back on my old centos 6.8 but on 7 all it does is to display the Apache test page and all directories and files inside forum show as forbidden. Why is that?

UPDATE: /www/html/forum is the document root and the site is accessed by a "parked domain" (example.com).

1

UPDATE: The assumptions made here are wrong so this answer is mostly irrelevant now. This answer is just for future reference.


We're going to have to make some assumptions to answer this...

  • /www/html is your document root and therefore /forum is a subdirectory, off the document root in which this .htaccess file is located.
  • All requests should be relative to the /forum subdirectory. (Which I assume is why this .htaccess file is in the /forum subdirectory.)

Try changing your directives to the following:

RewriteEngine On
RewriteBase /forum
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule \.(jpeg|jpg|gif|png)$ public/404.php [NC,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]

Note that I've changed the RewriteBase directive and made both RewriteRule substitutions relative (ie. no slash prefix).

instead of looking like example.com/index.php?user=222 it would look like example.com/user/222.

I'm assuming that everything is in the /forum subdirectory, so this would need to be present in both these URLs: example.com/forum/index.php?user=222 and example.com/forum/user/222 respectively. You would only be able to remove the /forum subdirectory from the URL if this .htaccess file was in the document root. (If a request of the form example.com/index.php?user=222 worked successfully then "something else" is going on here.)

This worked fine back on my old centos 6.8 but on 7 all it does is to display the Apache test page

I don't really see how this could have worked on your "old centos 6.8", unless you had a different directory structure and this was all in the document root and not a subdirectory?

I can only assume that the "Apache text page" is index.php in the document root? Otherwise, where is this located?

  • the url is example.com without the forum because the parked domain is pointing to forum so forum is the root directory of that domain. That apache page I dont know where it is. – Cain Nuke Apr 30 '17 at 5:03
  • Ah OK, that completely changes things. Do you have any other .htaccess files along the filesystem path? What do you get if you simply request example.com/index.php (example.com being your parked domain)? Presumably /user is not a physical subdirectory? Are you externally redirected to the "Apache test page"?? – MrWhite Apr 30 '17 at 8:35
  • No, I have only that htaccess. example.com/index.php gives me a forbidden page and user is not a subdirectory. – Cain Nuke May 1 '17 at 5:24
  • Curious, example.com/index.php gives you a "forbidden page" (403?), but example.com/index.php?user=222 routes OK? Or is that only when the .htaccess directives are temporarily removed? (Although, if you access example.com/index.php or example.com/index.php?user=222 it really shouldn't matter whether this .htaccess file exists or not - since those directive won't do anything if you access /index.php directly - assuming this is a physical file. ???) – MrWhite May 1 '17 at 9:05
  • No, all urls will give me a forbidden page except example.com which shows the apache test page. – Cain Nuke May 2 '17 at 23:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.