I have been working on htaccess rewrite rule for below 2 urls:
example.com/main-page.php?pagename=web-hosting which changes to example.com/basichosting/web-hosting
example.com/sub-page.php?pagename=vps-server which changes to example.com/advancedhosting/vps-server
I use the following .htaccess rewrite rule and it works
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [NC,L]
RewriteRule ^basichosting/([A-Za-z0-9_'-]+)$ main-page.php?pagename=$1 [L]
RewriteRule ^advancedhosting/([A-Za-z0-9_'-]+)$ sub-page.php?pagename=$1 [L]
What I actually want is my urls to look like
example.com/hosting/web-hosting
example.com/hosting/vps-server
Is it possible to change 'basichosting' and 'advancedhosting' to 'hosting' for the corresponding page name
Or else is it possible to hide 'basichosting' and 'advancedhosting' from the urls.
If so how can I write my htaccess rewrite rule?
My htaccess:
RewriteEngine On
##Rules for existing php files rewrite.
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)/?$ $1.php [NC,L]
##Rules for external rewrite to hosting uri as per OP need.
RewriteCond %{THE_REQUEST} \s/main\.php\?pagename=(\S+)\s [NC]
RewriteRule ^ /hosting/%1? [R=301,L]
##Rules for internal rewrite to main.php file.
RewriteRule ^(?:[^/]*)/(.*)/?$ main.php?pagename=$1 [L]
##Rules for external rewrite to hosting uri as per OP need.
RewriteCond %{THE_REQUEST} \s/sub\.php\?pagename=(\S+)\s [NC]
RewriteRule ^ /hosting/%1? [R=301,L]
##Rules for internal rewrite to sub.php file.
RewriteRule ^(?:[^/]*)/(.*)/?$ sub.php?pagename=$1 [L]
<IfModule php5_module>
php_flag asp_tags Off
php_flag display_errors Off
php_value max_execution_time 30
php_value max_input_time 60
php_value max_input_vars 3000
php_value memory_limit 64M
php_value post_max_size 8M
php_value session.gc_maxlifetime 1440
php_value session.save_path "/var/cpanel/php/sessions/ea-php56"
php_value upload_max_filesize 2M
php_flag zlib.output_compression Off
</IfModule>
<IfModule lsapi_module>
php_flag asp_tags Off
php_flag display_errors Off
php_value max_execution_time 30
php_value max_input_time 60
php_value max_input_vars 3000
php_value memory_limit 64M
php_value post_max_size 8M
php_value session.gc_maxlifetime 1440
php_value session.save_path "/var/cpanel/php/sessions/ea-php56"
php_value upload_max_filesize 2M
php_flag zlib.output_compression Off
</IfModule>
<IfModule mime_module>
AddHandler application/x-httpd-ea-php56 .php .php5 .phtml
</IfModule>