How to Rewrite URL in htaccess with php?

Can you help me with .htaccess

  • Help with modifying an .htaccess file. I'm on Dreamhost and using Expression Engine, if that makes any diff. Disclaimer: I know nothing of the .htaccess thingy and have never touched it before. Please explain as if speaking to an idiot! I use the Expression Engine CMS which defaults to putting index.php in a url, like this: www.mydomain.com/index.php/template/ According to http://www.eewiki.com/wiki?title=Remove_index.php_From_URLs in the EE wiki, I can configure .htaccess to omit the index.php so it looks like this www.mydomain.com/template/ However, I cannot make head nor tail of the instructions there. I use Dreamhost as my host and do not see an .htaccess file in the root. They do have .htaccess in their control panel and when I click it it asks me to create a new directory. Hence, I'm lost. Any suggestions?

  • Answer:

    If you're connecting via FTP, you might need to turn on a preference in your FTP client to show "invisible files," files that start with "." like .htacess. If you're using webftp.dreamhost.com, those files should show up automatically. If you don't see any .htaccess file, you just need to create a new one. Then you need to add something like this to the file: RewriteEngine On RewriteRule ^/template/(.*)$ /index.php/template/$1 (I haven't tested that, so it may be wrong.)

You Should See the Other Guy at Ask.Metafilter.Com Visit the source

Was this solution helpful to you?

Other answers

scottreynen, the wiki lists this code: RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /index.php/$1 [L] However, when I save it to a file and call the file .htaccess and upload it, I then get a server 500 error from my site.

You Should See the Other Guy

www.mydomain.com/index.php/template/ According to this page in the EE wiki, I can configure .htaccess to omit the index.php so it looks like this www.mydomain.com/template/Are you looking to access www.mydomain.com/index.php/template/ or www.mydomain.com/template/index.php/? If the latter, you could just add the following line to your .htaccess: DirectoryIndex index.php

Doofus Magoo

Doofus, EE adds /index.php after the domain name. Doing what you suggest would render as www.mydomain.com/index.php/template/index.php/ I want to get rid of the first index.php

You Should See the Other Guy

A 500 error that shows up after you add .htaccess files generally means the redirect is sending the server in an endless loop. Do the wiki instructions say where you should put the .htaccess file? I think maybe you need to create a directory named "template" and put the .htaccess file in there if you want the address to be domain.com/template/.

scottreynen

Meta hint: you might want to change your .htaccess tag to htaccess because the .htaccess tag returns a 403 when browsing the tag.

Mitheral

It doesn't specify. However, there are multiple templates not just one.

You Should See the Other Guy

Does the htaccess file have to have certain permissions set?

You Should See the Other Guy

Can't recall where I spotted this today, but here is a .htaccess file generator: http://cooletips.de/htaccess/

boost ventilator

Thanks, all! Got it working! (textedit was doing something to the file. I opened it in the ftp program and it looked all screwy. rewrote it in there, uploaded, worked!)

You Should See the Other Guy

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.