Pretty URL .htaccess rewrite subdomain to directory

The place to talk about things that are related to CMS Made simple, but don't fit anywhere else.
Locked
User avatar
magallo
Forum Members
Forum Members
Posts: 105
Joined: Thu Mar 24, 2011 12:37 am

Pretty URL .htaccess rewrite subdomain to directory

Post by magallo »

hi guys, i need help figuring out how to .htaccess rewrite subdomain to directory and keep subdomain in url

For example, i need the result of this url:
https://mywebsite.com/reviews/name

to appear like this:
https://reviews.mywebsite.com/name

The content of https://mywebsite.com/reviews/name is generated by LISE and works as expected using the default .htaccess provided by cmsms.

Code: Select all

<IfModule rewrite_module>

Thanks in advance.

	RewriteEngine on
	# If your CMSMS installation is in a subdirectory of your domain, you need to specify the relative path (from the root of the domain) here.
	# In example: RewriteBase /[subdirectory name]
	RewriteBase /
    
    # +++++ ADD THIS - START +++++
      # Link to http(s)://www.website.com then redirect to https://website.com
      RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
      RewriteRule ^(.*)$ https://%1/$1 [R=301,L]

      # Force URLs have https instead of http
      RewriteCond %{HTTPS} off
      RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    # ++++++ ADD THIS - END +++++
	
	# Rewrites URLs in the form of /parent/child/grandchild but only rewrites if the requested URL is not a file or directory.
	RewriteCond %{REQUEST_FILENAME} !-f
	RewriteCond %{REQUEST_FILENAME} !-d
	RewriteRule ^(.+)$ index.php?page=$1 [QSA]
</IfModule>
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3483
Joined: Mon Nov 28, 2011 9:29 am
Location: The Netherlands

Re: Pretty URL .htaccess rewrite subdomain to directory

Post by velden »

First of all .htaccess rewrite rules are typically used to rewrite request urls, not to generate urls in webpages.

The generation of the url should be done from within the LISE template probably.

I think the rewriting back (from https://reviews.mywebsite.com/name to https://mywebsite.com/reviews/name) may be done within the .htaccess rewrite rules. But probably depends on the configuration of your web environment. If you actually serving the sub domain from a separate folder, you may be able to do it by adding the .htaccess file with proper rules there.
If the subdomain 'points' to the webroot (where CMSMS is installed) you should able to use the .htaccess from that folder to rewrite the url.
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Re: Pretty URL .htaccess rewrite subdomain to directory

Post by calguy1000 »

The ,.htaccess file ONLY handles incoming requests, it does not transform URLS the output HTML generated by the web application.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
User avatar
magallo
Forum Members
Forum Members
Posts: 105
Joined: Thu Mar 24, 2011 12:37 am

Re: Pretty URL .htaccess rewrite subdomain to directory

Post by magallo »

I ended up pointing the subdomain to the same folder where the main site is. I then edited the LISE item url to only have:
name
instead of
reviews/name

It works but i need to make sure search engine doesn't see duplicate content.
User avatar
Dr.CSS
Moderator
Moderator
Posts: 12709
Joined: Thu Mar 09, 2006 5:32 am
Location: Arizona

Re: Pretty URL .htaccess rewrite subdomain to directory

Post by Dr.CSS »

You should be able to add a subdomain in your cPanel which will give you that URL no need for htaccess except maybe for pretty URLs and...

#Sub-dir e.g: /cmsms
RewriteBase /reviews

I how I do all mine...
Locked

Return to “The Lounge”