[Solved] Pretty URL - subdomain gives Internal Server Error

For questions and problems with the CMS core. This board is NOT for any 3rd party modules, addons, PHP scripts or anything NOT distributed with the CMS made simple package itself.
Locked
KayJayDK
New Member
New Member
Posts: 5
Joined: Fri Jan 24, 2014 9:07 am

[Solved] Pretty URL - subdomain gives Internal Server Error

Post by KayJayDK »

I'm running CMSMS 1.11.9 on an Apache server.
I have enabled pretty URLs using the guide at http://docs.cmsmadesimple.org/configuration/pretty-url and it is working fine with pages set up through CMSMS both with domain/page and page.domain.
Setting up a subdomain by creating a folder on the server also works with domain/subdomain and subdomain.domain.

If I enter a page that does not exist with domain/nopage I get the expected 404 but using nopage.domain gives me a 500 Internal Server Error.

I have used the .htaccess file from the Docs folder of the CMS installation and done everything in the above guide. Since I don't know much about URL rewriting I have not attempted to alter anything so I hope someone could point me in the right direction.
Last edited by KayJayDK on Fri Jan 24, 2014 9:37 pm, edited 1 time in total.
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3497
Joined: Mon Nov 28, 2011 9:29 am

Re: Pretty URL - subdomain gives Internal Server Error

Post by velden »

If you rename/remove the .htaccess file you don't get a 500 error?
KayJayDK
New Member
New Member
Posts: 5
Joined: Fri Jan 24, 2014 9:07 am

Re: Pretty URL - subdomain gives Internal Server Error

Post by KayJayDK »

Removing .htaccess restores the default behaviour (404 page).
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3497
Joined: Mon Nov 28, 2011 9:29 am

Re: Pretty URL - subdomain gives Internal Server Error

Post by velden »

I don't know what causes this. Don't know if the error log of the web server might contain some additional information.

You could make a copy of the .htaccess file and comment out some 'blocks'. There is more in it than just url rewriting.

I *think* this is all you need for Pretty urls

Code: Select all

<IfModule mod_rewrite.c>
RewriteEngine on
#
#Sub-dir e.g: /cmsms
RewriteBase /

# 301 Redirect all requests that don't contain a dot or trailing slash to
# include a trailing slash
# but ignore POST requests.
#RewriteCond %{REQUEST_URI} !/$
#RewriteCond %{REQUEST_URI} !\.
#RewriteCond %{REQUEST_METHOD} !POST$
#RewriteRule ^(.*) %{REQUEST_URI}/ [R=301,L]

# Rewrites urls in the form of /parent/child/
# 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>
KayJayDK
New Member
New Member
Posts: 5
Joined: Fri Jan 24, 2014 9:07 am

Re: Pretty URL - subdomain gives Internal Server Error

Post by KayJayDK »

I slimmed down the .htaccess as you suggested and you are right, it only needs that little snippet... no change in behaviour, though.

I added a new rewrite which takes anything in front of my domain name and appends it after. This works as intended but I'm not sure if it will give me other problems later on. Also, I would like to make it more general, ie. not needing the 'mysite.com' but at least this seems to work.

Code: Select all

<IfModule mod_rewrite.c>
RewriteEngine on
#
#Sub-dir e.g: /cmsms
RewriteBase /

RewriteEngine on
RewriteCond %{HTTP_HOST} ^(.*)\.mysite\.com
RewriteRule ^(.*)$ http://mysite.com/$1 [L,NC,QSA]

# Rewrites urls in the form of /parent/child/
# 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
Dr.CSS
Moderator
Moderator
Posts: 12711
Joined: Thu Mar 09, 2006 5:32 am

Re: Pretty URL - subdomain gives Internal Server Error

Post by Dr.CSS »

You can use the full htaccess from the doc folder you just have to add the name of the subdomain folder to this line to get pretty URLs to work...

RewriteBase /
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3497
Joined: Mon Nov 28, 2011 9:29 am

Re: Pretty URL - subdomain gives Internal Server Error

Post by velden »

Dr.CSS wrote:You can use the full htaccess from the doc folder you just have to add the name of the subdomain folder to this line to get pretty URLs to work...

RewriteBase /
I don't think so.
JohnnyB
Dev Team Member
Dev Team Member
Posts: 731
Joined: Tue Nov 21, 2006 5:05 pm

Re: Pretty URL - subdomain gives Internal Server Error

Post by JohnnyB »

I think you have to hardcode the domain in that example. If you didn't care if the prefix in front of the domain was part of the rewriterule, you could use %{HTTP_HOST) instead of the domain.

AFAIK, the $1 is just going to carry of the query string in the URI

For example, ;http://subdomain.domain.com/index.php?page=foo
will be rewritten as ;http://domain.com/foo

Is that what you want or are you trying to get,
;http://domain.com/subdomain/foo ??


Or are you trying to make sure that any subdomain or prefix in front of your domain is removed before rewriting to SEF URLs (pretty urls)?
Last edited by Dr.CSS on Sat Jan 25, 2014 5:16 pm, edited 1 time in total.
Reason: Please use double quotes or something on fake links so they aren't clickable...
"The art of life lies in a constant readjustment to our surroundings." -Okakura Kakuzo

--
LinkedIn profile
--
I only speak/write in English so I may not translate well on International posts.
--
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3497
Joined: Mon Nov 28, 2011 9:29 am

Re: Pretty URL - subdomain gives Internal Server Error

Post by velden »

JohnnyB wrote:AFAIK, the $1 is just going to carry of the query string in the URI
Nope. It will take anything after the domain name and paste that after the hard coded 'http://mysite.com

Just curious what you're trying to do? What do you expect visitors to type you don't want then to?
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3497
Joined: Mon Nov 28, 2011 9:29 am

Re: Pretty URL - subdomain gives Internal Server Error

Post by velden »

BTW: I think it might be better/more efficient to change the rule little:

Code: Select all

RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^mysite\.com [NC]
RewriteRule (.*) http://mysite.com/$1 [R=301,L]
It's probably a lot easier for the engine to check for the condition that it's NOT something (in this case it's not 'mysite.com'. Why check for all posibilities in the world when you only want one to be accepted?

[R=301] makes the browser redirect and let it know that it is a 'Permanent Move'. That's good for search engines so they 'know' they should not index those urls.
KayJayDK
New Member
New Member
Posts: 5
Joined: Fri Jan 24, 2014 9:07 am

Re: Pretty URL - subdomain gives Internal Server Error

Post by KayJayDK »

What I'm trying to achieve is for my CMS to work with pretty URLs which it does.
I often add folders (or subdomains) manually with content apart from the CMS to share with other or to test some functions.
I would like to be able to access either as both a subdomain or as a static page (the user does not need to know which they are accessing).
Also, I want any nonexisiting pages/subdomains typed in to use my custom made error page in the CMS.

The example I made above kind of works but it will make sub.subdomain.domain appear as domain/sub.subdomain.

It's OK that the domain name is hardcoded, I just wanted it to be easy to use on other domains but it's a small change that would need to be done.
KayJayDK
New Member
New Member
Posts: 5
Joined: Fri Jan 24, 2014 9:07 am

Re: Pretty URL - subdomain gives Internal Server Error

Post by KayJayDK »

Velden, your suggestion works perfectly as long as I stay away from sub-subdomains (eg. sub.subdomain.domain.com) which I don't use anyway.
The main problem was the Server Error if you enter a subdomain that doesn't exist and that problem is now solved :)

I have now learned a little bit more about URL rewrites and half the trick is to learn you RegExps... but there seems to be some kind of voodoo element to it as well, reading the problems people have with their .htaccesses.

Thanks for the input from everyone. Now I can focus in the site again but I will return to this thread and see if I can learn exactly what I have just been doing :D
User avatar
Dr.CSS
Moderator
Moderator
Posts: 12711
Joined: Thu Mar 09, 2006 5:32 am

Re: [Solved] Pretty URL - subdomain gives Internal Server Er

Post by Dr.CSS »

I use the default htaccess from the doc folder and the RewriteBase / to make sudomain sites with pretty URLs all the time and it work perfect, look at the album link below...
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3497
Joined: Mon Nov 28, 2011 9:29 am

Re: [Solved] Pretty URL - subdomain gives Internal Server Er

Post by velden »

I think Rewrite/.htaccess behavior regarding subdomains can be different for different web server configurations.
Locked

Return to “CMSMS Core”