Htaccess is one clean url but not another

Htaccess files have never been a strong point for me, unfortunately.

I'll just jump straight:

#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, switching to domain.com/account/index.php?page=page works, but switching to domain.com/account/page/ doesn't, it just returns 404 Not Found.

page variables can be things like login , create , dashboard and logout , etc. index.php in the account directory will handle this variable.

I am confused by the question of why this does not work in the same situation, just in a different directory and a different file name, but both of them are declared in the rule. Anyone now what am I doing wrong?

EDIT

I also tried to do this and define the pages, for example:

  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 404

+4
source share
5 answers

Replace the account in the themes directory in the RewriteRule.

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

If this works, check if there is any other .htaccess in the help directory there. If you cannot find any other file, check also for any conflicting RewriteRule (s) in httpd.conf (in <Directory> tags).

If nothing is given, mark your rule as [L] ast ie mod_rewrite should stop processing it.

 RewriteRule ^account/([a-zA-Z0-9]+)/$ account/index.php?page=$1 [L] 
+2
source

I tried it locally and could not reproduce it. The account is working fine.

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

  • follow the answer of Ravi Taplial .

Other points are obvious:

  • Please make sure you spell your account name "fold" and index.php correctly

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

+2
source

You currently do not match the action page due to hypen by adding a hyphen as part of the matching character set resolves this

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

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] 

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

0
source

I see several errors in your .htaccess:

  • Using RewriteCond %{REQUEST_FILENAME} !-f and RewriteCond %{REQUEST_FILENAME} !-d only for the themes rule, but skipping the account rule.
  • Do not complete rewrite rules with the L (last) flag.
  • Do not use the QSA (Query String Append) flag to save 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] 
0
source

Source: https://habr.com/ru/post/1481963/


All Articles