Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP Drupal Basics Site Building with the Drupal Interface Drupal Nodes and URLs

Fábio Tavares da Costa
Fábio Tavares da Costa
11,985 Points

Clean URL does not work. Options please.

Hi,

Mimicking the process used by Diane to enable cleans URLs did not work as well as the options under Config >> SEARCH AND METADATA.

Can I have a handcraft alternative, please?

4 Answers

The reason your drupal install can't create clean urls is because it has to be enabled by the .htaccess file located in the root of your drupal installation.

Oddly enough, the default download for drupal metioned in the course doesn't contain the .htaccess file.

Go to the root of your site, and create a .htaccess file. I got this from the new home of their core files, github.

https://raw.githubusercontent.com/drupal/drupal/7.x/.htaccess

Aaron Munoz
Aaron Munoz
11,177 Points

You'll want to also make sure Apache is set to allow this as well.

Fábio Tavares da Costa
Fábio Tavares da Costa
11,985 Points

Thanks everyone,

I fixed it yesterday. In my case the missing code were...

~ $ cat /etc/apache2/sites-available/web.dev.conf 
<VirtualHost *:80>
    ServerAdmin admin@web.dev
    ServerName web.dev
    ServerAlias www.web.dev
    DocumentRoot /srv/web.dev
        # ...these lines.
    <Directory /srv/web.dev>
        Allowoverride All
    </Directory>
        # DONE!
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

Well, that's what @Aarom is talking about.

And, any way this .htaccess file is handy.

Matthew Roberts
Matthew Roberts
11,459 Points

I came across this problem using XAMPP on windows. As my site files are all kept in a separate folder from XAMPP, the clean URL test in the Drupal Configuration page failed. My solution (after much searching!) was simply as follows:

Open your .htaccess file in your drupal folder and find the following:

 # Modify the RewriteBase if you are using Drupal in a subdirectory or in a
  # VirtualDocumentRoot and the rewrite rules are not working properly.
  # For example if your site is at http://example.com/drupal uncomment and
  # modify the following line:
  # RewriteBase /drupal
  #
  # If your site is running in a VirtualDocumentRoot at http://example.com/,
  # uncomment the following line:
  # RewriteBase /

then uncomment (remove the # from before) the last line RewriteBase /

After this, restart your XAMPP (or WAMPP etc) for good measure and re-try enabling clean-urls in Drupal.

I know this problem has already been solved for the original poster but hopefully it'll help out someone else stumbling across this problem!