Hi,

I want a URL alias that matches the name of my files directory. Cannot find a way is this possible?

Cheers

Comments

cog.rusty’s picture

If your files directory is, for example, files then try this. In your .htaccess file change the last block of lines

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

to

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d [OR]
RewriteCond %{REQUEST_URI} ^/files/$
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

Then you should be able to use the files path as an alias and still access the files under it.

evo’s picture

Thanks for your reply, but at the moment my files .htaccess has:

SetHandler Drupal_Security_Do_Not_Remove_See_SA_2006_006
Options None
Options +FollowSymLinks

I pasted your suggestion but it did not work...?

cog.rusty’s picture

Not that one. That is only for security purposes. I meant the main .htaccess file in Drupal's directory.

evo’s picture

It is not working. My files directory has been renamed to 'resources' so I have changed the .htaccess to:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d [OR]
RewriteCond %{REQUEST_URI} ^/resources/$
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

Should this still work even though it is not 'files'?

Thanks

cog.rusty’s picture

Yes, it should work if that directory is located under your web root (if it is http://www.example.com/resources)

What exactly happens when you go there?

evo’s picture

I get a 404 error 'Not Found'. Could the error be that I am viewing it from my local host e.g. http://localhost/example/resources?

cog.rusty’s picture

In that case, try ^/example/resources/$

evo’s picture

All good it was a localhost problem. I tried it online and your original idea worked perfect.

Thanks for your help!

evo’s picture

I have an additional problem based on this. In my files directory (called 'resources') I have subfolders of some content types that contain the content types files. One content type is called 'Tutorials' and I have a views page that lists all tutorials. I want a URL that goes http://example.com/resources/tutorials that links to this view page, but I cannot get it to work with the above method. Can anybody help?

cog.rusty’s picture

To let the subdirectories be handled by Drupal as well, try removing the last $ from the previous method:

...  [OR]
RewriteCond %{REQUEST_URI} ^/resources/
...

If this does not work, and makes your files not appear in the view, then try adding lines for the additional subdirectories:

... [OR]
RewriteCond %{REQUEST_URI} ^/resources/$ [OR]
RewriteCond %{REQUEST_URI} ^/resources/tutorials/$

Heh, usually people try to do the opposite, to make Drupal leave their subdirectories alone, not to take them over.

evo’s picture

Both ways worked like a charm, much appreciated.

cog.rusty’s picture

Nice, I was worried that with the first method the file links wouldn't work.