Question

Rewrite Rule in .htaccess file for subdomain

Hi,

I have configured my Blog on http://blog.example.com. For this I have an Apache Conf file which direct the user to /blog directory.

I have two major issues:

1.) After installation, when I try to open admin panel from http://blog.example.com/admin/login, it throws 500 Internal Server Error. It seems the rewrite engine is not properly coded in the .htaccess file.

Also when I try to open the admin link, it takes me to: http://www.example.com/admin/login in place of http://blog.example.com/admin/login. This is bound to throw an error.

2.) When I open the site, http://blog.example.com, it opens normally, but when I click on the default 1st blog, again the Server throw 500 Internal Error and takes me to http://www.example.com/posts/my-blog in place of http://blog.example.com/posts/my-blog.

I think it has something to do with .htaccess file which sends rewrite information to server, which is incorrect.

Can you please advice what should be the edit for: <pre> RewriteRule ^(.*)$ index.php/$1 [L] </pre> so that I can remove index.php from the URL as well as keep the link to http://blog.example.com/ while browsing the blog?


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Also Check this code for redirection with .index.htm to non www url

Options +FollowSymLinks

RewriteEngine on

RewriteCond %{HTTP_HOST} !^http://www.brother.printersupportaustralia.net [NC]

RewriteRule ^(.*)$ http://brother.printersupportaustralia.net/$1 [L,R=301]

 

RewriteCond %{REQUEST_URI} ^(.*)//(.*)$

RewriteRule . http://brother.printersupportaustralia.net%1/%2 [R=301,L]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(([^/]+/)*)index\.htm\ HTTP/

RewriteRule index\.htm$ http://brother.printersupportaustralia.net/%1 [R=301,L]\


Let’s start simple:

in your apache config (/etc/httpd/conf/httpd.conf or /etc/apache2/apache2.conf), do you have this uncommented: <pre> NameVirtualHost *:80 </pre> If not, uncomment that, and restart httpd

Next, most blogging software won’t allow multiple domains in one folder. You’ll need a separate folder per domain/sub-domain. If you’re not doing this, you will need to separarate that.

Almost done. Let’s go back to the apache config (Look at my 2nd line for the file again)

Do you have something like this for your vhost: <pre> AllowOverride All </pre> or is it something like this: <pre> AllowOverride None </pre> If the latter, it won’t work, and you’ll need to change it (This doesn’t apply to the cgi-bin or error folders, just your document root).

Next to last: do you have mod_rewrite enabled? For Ubuntu, you would run this: <pre> a2enmod rewrite; service apache2 reload </pre> Finally: do you have the permission set for the web user (apache/www-data) to have read access to your .htaccess file?

If you’re unsure of any of the answers to these questions, just let me know.

Jon

Is it wrtite code from www to non www version.

RewriteEngine On

RewriteCond %{HTTP_HOST} ^http://www.brother.printersupportaustralia.net$ [NC]
RewriteRule ^(.*)$ http://brother.printersupportaustralia.net/$1 [R=301,L]