N
N
Nikita Paskal2015-01-19 21:25:31
PHP
Nikita Paskal, 2015-01-19 21:25:31

How to merge htaccess?

Good day to all! I want to combine two htaccess files, but unfortunately I don't know their syntax, so I don't know how to combine the following two fragments:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ profile. php?username=$1
and this
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
The first one does and addresses the form profile.php?username=bob The address of the form is simply bob . The second removes the endings .php in the line. But then there is a problem. For example, when it gets to the news page, it is treated as a user and throws an error. How to implement a combination of these fragments? If this cannot be implemented, then a variant of the type may be possible: user / bob ? Thanks in advance

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Danil Chekalin, 2015-01-20
@paskalnikita

RewriteEngine On
RewriteRule ^user/(.+)$ /profile.php?username=$1 [L] # все запросы user/* будет обрабатывать profile.php

RewriteCond %{REQUEST_FILENAME}\.php -f # если {query}.php
RewriteRule ^(.*)$ $1.php # то {query} будет обрабатывать {query}.php

Condition RewriteCond %{REQUEST_FILENAME} !-d I didn't include it in the code intentionally for clarity

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question