4

htaccess files have never been a strong point for me unfortunately.

I'll just jump right in:

#Turn RewriteEngine on
    Options +FollowSymLinks
    RewriteEngine on


#Canonicalize URL
    RewriteCond %{HTTP_HOST} !^www\.domain-removed\.com [NC]
    RewriteCond %{HTTP_HOST} !^$
    RewriteRule ^/?(.*) http://www.domain-removed.com/$1 [L,R,NE]


#Add Trailing Slash
    RewriteCond %{REQUEST_URI} !(/$|\.) 
    RewriteRule (.*) %{REQUEST_URI}/ [R=301,L]


#Clean URLs
    RewriteCond %{SCRIPT_FILENAME} !-d
    RewriteCond %{SCRIPT_FILENAME} !-f

    RewriteRule ^themes/([a-zA-Z0-9]+)/$ themes/view.php?theme=$1
    RewriteRule ^account/([a-zA-Z0-9]+)/$ account/index.php?page=$1

So going to domain.com/themes/theme-name/ and domain.com/themes/view.php?theme=theme-name works fine and both show the same page/results. However, going to domain.com/account/index.php?page=page works but going to domain.com/account/page/ doesn't, it just returns a 404 Not Found.

page variables can be things such as login, create, dashboard and logout etc. The index.php in the account directory will process this variable.

It's confusing me as to why it doesn't work as it's the same situation, just under a different directory and a different file name, but both are declared in the rule. Anyone now what I'm doing wrong?

EDIT

I've also tried doing this and defining the pages, like so:

    RewriteRule ^account/login/$ account/login.php
    RewriteRule ^account/logout/$ account/logout.php
    RewriteRule ^account/create/$ account/create.php
    RewriteRule ^account/dashboard/$ account/dashboard.php

But still it just returns a 404

no.
  • 2,356
  • 3
  • 27
  • 42

5 Answers5

2

Replace account with themes directory in your RewriteRule.

RewriteRule ^account/([a-zA-Z0-9]+)/$ themes/view.php?theme=$1

If this works check if there's any other .htaccess under the account directory interfering here. If you're unable to find any other file also check for any conflicting RewriteRule(s) in httpd.conf (under <Directory> tags).

If nothing gives, mark your rule as [L]ast i.e. mod_rewrite should stop processing it any more.

RewriteRule ^account/([a-zA-Z0-9]+)/$ account/index.php?page=$1 [L]
Ravi K Thapliyal
  • 51,095
  • 9
  • 76
  • 89
2

I tried it out locally and couldn't reproduce it. The account works fine.

  • I had problems with your redirect to domain-removed.com. Are your sure you want to redirect all requests to this domain?.

  • follow Ravi Thapliyal's answer.

The other points are obvious:

  • Please make sure you spell the name of your fold 'account' and the index.php correctly

  • When trying RewriteRule ^account/login/$ account/login.php make sure login.php exists.

gamag
  • 423
  • 5
  • 14
0

Currently you aren't matching action-page because of the hypen, adding a hyphen as part of the character set being matched will resolve this

RewriteRule ^account/([a-zA-Z0-9-]+)/$ account/index.php?page=$1
theGreener
  • 21
  • 2
  • Apologies, that was my mistake, `action-page` just referred to a page such as `login` or `create`, I completely forgot to mention! I'll edit now! – no. May 21 '13 at 14:13
0

Try adding [L,PT] to the RewriteRule directives.

RewriteRule ^themes/([a-zA-Z0-9]+)/$ themes/view.php?theme=$1 [L,PT]
RewriteRule ^account/([a-zA-Z0-9]+)/$ account/index.php?page=$1 [L,PT]

Reference: http://httpd.apache.org/docs/current/rewrite/flags.html#flag_l

Subhas
  • 14,290
  • 1
  • 29
  • 37
0

I can see few mistakes in your .htaccess like:

  1. Using RewriteCond %{REQUEST_FILENAME} !-f and RewriteCond %{REQUEST_FILENAME} !-d only for themes rule but skipping account rule.
  2. Not ending Rewrite rules with L (Last) flag.
  3. Not using QSA (Query String Append) flag to preserve the query string.

Here is your modified .htaccess that you should try:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

# force www.domain-removed.com domain
RewriteCond %{HTTP_HOST} !^www\.domain-removed\.com$ [NC]
RewriteRule ^(.*)$ http://www.domain-removed.com/$1 [L,R=302,NE]

# add trailing slash
RewriteRule (?!^(?:.*?/|.+?\..*)$)^.*$ %{REQUEST_URI}/ [R=302,L]

## Clean URLs  

# do nothing for real files, directories or sym-links
RewriteCond %{SCRIPT_FILENAME} -d [OR]
RewriteCond %{SCRIPT_FILENAME} -f [OR]
RewriteCond %{SCRIPT_FILENAME} -l
RewriteRule - [L]

# no handle /themes/ and /account/ URIs
RewriteRule ^themes/([a-zA-Z0-9]+)/?$ /themes/view.php?theme=$1 [L,QSA]

RewriteRule ^account/([a-zA-Z0-9]+)/?$ /account/index.php?page=$1 [L,QSA]
anubhava
  • 761,203
  • 64
  • 569
  • 643
  • QSA is not required since OP is matching on directories without any query string. Likewise, the "!-d" condition when not in effect shouldn't affect redirection. But, yes it's a good catch and OP should fix it once the issue is resolved. – Ravi K Thapliyal May 31 '13 at 06:40