Настройка хороших URL-адресов htaccess

Я впервые использую htaccess для создания хороших URL-адресов для моих html-файлов и 1 php-файла. Мне просто интересно, смогу ли я получить совет по моему файлу htaccess, и если я его настроил, это хороший способ? Я бы не хотел, чтобы мои URL не работали в какой-то ситуации из-за того, что я написал. 🙁

Пример файла html:

before: http://www.domain.com/subdomain/htmlpage.html after: http://www.domain.com/subdomain/htmlpage/ 

Один файл php:

 before: http://www.domain.com/subdomain/phppage.php?p=1 after: http://www.domain.com/subdomain/phppage/1/ 

Я добавил в правило перенаправление index.html на index.php. Мне также пришлось добавить «base href» в начало каждого файла, потому что я использовал относительные ссылки.

файл htaccess:

 Options +FollowSymLinks RewriteEngine on RewriteRule ^index\.html?$ / [NC,R,L] RewriteCond %{REQUEST_FILENAME} !-f RewriteRule .*[^/]$ %{REQUEST_URI}/ [L,R=301] RewriteCond %{REQUEST_FILENAME}.html -f RewriteRule ^(.+)/$ $1.html [L] RewriteRule ^(.+)/([0-9]+)/?$ phppage.php?p=$1 [L] 

Эта строка

 RewriteRule ^(.+)/([0-9]+)/?$ phppage.php?p=$1 [L] 

собирается отправлять некоторые страницы на phppage.php, даже если они не похожи

 http://www.domain.com/subdomain/phppage/1/ 

потому что в первом аргументе RewriteRule нет упоминания о phppage.

попробуйте добавить следующее в ваш .htaccess файл в корень вашего домена

 Options +FollowSymLinks RewriteEngine On RewriteBase / # redirect http://www.domain.com/subdomain/htmlpage.html to http://www.domain.com/subdomain/htmlpage/ RewriteCond %{REQUEST_URI} ^(/subdomain/[^/]+)\.html$ [NC] RewriteRule . %1/ [L,R=301] #redirect http://www.domain.com/subdomain/phppage.php?p=1 to http://www.domain.com/subdomain/phppage/1/ RewriteCond %{REQUEST_URI} ^(/subdomain/[^/]+)\.php$ [NC] # or alternatively if page is literally phppage uncomment below and comment above #RewriteCond %{REQUEST_URI} ^(/subdomain/phppage)\.php$ [NC] RewriteRule . %1/ [L,R=301] #if url does not end with / RewriteCond %{REQUEST_URI} ^(/subdomain/.+[^/])$ [NC] # and its not for an existing file RewriteCond %{REQUEST_FILENAME} !-f # put one trailing slash RewriteRule . %1/ [L,R=301] #write http://www.domain.com/subdomain/htmlpage/ to htmlpage.html RewriteCond %{REQUEST_URI} ^/subdomain/([^/]+)/$ [NC] RewriteRule . %1.html [L] #write http://www.domain.com/subdomain/phppage/1/ to phppage.php?p=1 RewriteCond %{REQUEST_URI} ^/subdomain/[^/]+/([0-9]+)/$ [NC] RewriteRule . phppage.php?p=%1 [L]