I use a support system and I want to rewrite the URLs to make them more SEO friendly and better readable. I have very basic understanding of .htaccess rewrite rules / regex and I tried a hundred things, but could not get it working.
The support system is installed on this URL:
http://www.example.com/help/
The code is generating this URL for every article in the KB:
http://www.example.com/help/index.php?/selfhelp/view-article/article-1
The code is generating this URL for the category overview within the KB:
http://www.example.com/hulp/index.php?/selfhelp/categories
How can I rewrite those URLs to something readable and SEO friendly like:
http://www.example.com/help/article/article-1
And for categories:
http://www.example.com/hulp/categories
If this is even possible? And if so, how can I do this using .htaccess.
Well you can make the friendly URLs work like this, and also redirect the old URLs:
# Rewrite new URLs
RewriteRule ^help/article/(.+)$ help/index.php?/selfhelp/view-article/$1 [E=rewritten:1]
RewriteRule ^help/categories$ help/index.php?/selfhelp/categories [E=rewritten:1]
# Redirect old URLs
RewriteCond %{ENV:rewritten} !=1
RewriteCond %{ENV:REDIRECT_rewritten} !=1
RewriteCond %{QUERY_STRING} ^/selfhelp/view-article/(.+)$
RewriteRule ^help/index\.php$ /help/article/%1 [R=301,L]
RewriteCond %{ENV:rewritten} !=1
RewriteCond %{ENV:REDIRECT_rewritten} !=1
RewriteCond %{QUERY_STRING} =/selfhelp/categories
RewriteRule ^help/index\.php$ /help/categories [R=301,L]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.