Page 1 of 1

[Solved] Pretty URL - subdomain gives Internal Server Error

Posted: Fri Jan 24, 2014 9:33 am
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.

Re: Pretty URL - subdomain gives Internal Server Error

Posted: Fri Jan 24, 2014 12:46 pm
by velden
If you rename/remove the .htaccess file you don't get a 500 error?

Re: Pretty URL - subdomain gives Internal Server Error

Posted: Fri Jan 24, 2014 12:57 pm
by KayJayDK
Removing .htaccess restores the default behaviour (404 page).

Re: Pretty URL - subdomain gives Internal Server Error

Posted: Fri Jan 24, 2014 1:12 pm
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>

Re: Pretty URL - subdomain gives Internal Server Error

Posted: Fri Jan 24, 2014 1:33 pm
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>

Re: Pretty URL - subdomain gives Internal Server Error

Posted: Fri Jan 24, 2014 6:07 pm
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 /

Re: Pretty URL - subdomain gives Internal Server Error

Posted: Fri Jan 24, 2014 7:40 pm
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.

Re: Pretty URL - subdomain gives Internal Server Error

Posted: Fri Jan 24, 2014 7:42 pm
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)?

Re: Pretty URL - subdomain gives Internal Server Error

Posted: Fri Jan 24, 2014 7:48 pm
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?

Re: Pretty URL - subdomain gives Internal Server Error

Posted: Fri Jan 24, 2014 8:03 pm
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.

Re: Pretty URL - subdomain gives Internal Server Error

Posted: Fri Jan 24, 2014 9:18 pm
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.

Re: Pretty URL - subdomain gives Internal Server Error

Posted: Fri Jan 24, 2014 9:36 pm
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

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

Posted: Sat Jan 25, 2014 5:05 pm
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...

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

Posted: Sat Jan 25, 2014 5:13 pm
by velden
I think Rewrite/.htaccess behavior regarding subdomains can be different for different web server configurations.