3

I have a file with name lang.php and another file in the same folder with same lang_inst.php. The .htaccess am using is:

RewriteEngine On
Options -Indexes
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^folder/lang folder/lang.php [NC,L]


RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)folder/lang_inst/([0-9a-zA-Z_-]+)/([0-9a-zA-Z_-]+) folder/lang_inst.php?lngid=$1&lngname=$2 [NC,L]

The problem is when I go to lng.php it is working well and good even if I type lng.klklk or lng we will be showing lng.php page only but when we try to view lng_inst.php page the we are getting the same content of lng.php page with total disturbed CSS. I mean the total design CSS everything is missing.

I have tried creating same page with other names and it's working well and good. I don't want to rename or recreate pages because I have so many pages like that. I mean files starting with same words (like sample.php sample_create.php).

Please help me to fix this.Please.

  • "The problem is when I go to lng.php" - presumably, you're not actually including the .php extension at all in the request (that's the point of your rewrite). But your example code assumes a request for /folder/lang, not lng.php. If you exemplify your code, the description still nees to match, otherwise it just becomes confusing. – MrWhite Jul 26 '18 at 10:27
1

A request for lng_inst.php will naturally get caught by the first, more generic, rule. You need to reverse your two rules, so the more specific rule is first. For example:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)folder/lang_inst/([0-9a-zA-Z_-]+)/([0-9a-zA-Z_-]+) folder/lang_inst.php?lngid=$1&lngname=$2 [NC,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^folder/lang folder/lang.php [NC,L]

You also need to disable MultiViews (which will otherwise override your directive to rewrite lang to lang.php), if you haven't already:

Options -Indexes -MultiViews

Alternatively, you could just make your first directive more specific (depending on your use case) and match exactly folder/lang and not any URL that starts with that URL. For example, change the RewriteRule pattern to read: ^folder/lang$ (additional trailing $).

Aside: Only use the NC (nocase) flag if you specifically need a case-insensitive match. For a rewrite, this is probably not the case, since you potentially create a duplicate content issue.

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.