开发者

How can I change URL and avoid that "?q=" appears?

开发者 https://www.devze.com 2023-03-14 12:17 出处:网络
I am using Ubuntu 10.10 + apache2 + php 5.33 + mysql + Drupal 7. My problem is the URLs used by Drupal are similar to the following one: http://localhost:808开发者_如何学Go0/drupal72/?q=node/1.

I am using Ubuntu 10.10 + apache2 + php 5.33 + mysql + Drupal 7.

My problem is the URLs used by Drupal are similar to the following one: http://localhost:808开发者_如何学Go0/drupal72/?q=node/1.

I want to remove the ?q=node/1 and replace it with some name /user or /book.


You want to add "Clean URLs" to your installation of drupal, see:

http://drupal.org/getting-started/clean-urls


Enabling clean URLs is the first step you should do. What you would get are URLs that appearsas http://example.com/node/1 (replace example.com with the domain of your Drupal site). If then you want a URL similar to http://example.com/books/clean-urls, then you should install Pathauto.

The Pathauto module automatically generates path aliases for various kinds of content (nodes, categories, users) without requiring the user to manually specify the path alias. This allows you to get aliases like /category/my-node-title.html instead of /node/123. The aliases are based upon a "pattern" system which the administrator can control.


On ubuntu you need to do only two things for clean urls to work first one is

sudo a2enmod rewrite

This is to enable rewrite module of apache. Second thing you need to do is, In your default apache host file which is located at

/etc/apache2/sites-available/default

In your file it will say

AllowOverride None

make it to

AllowOverride All

as follows.

DocumentRoot /var/www
<Directory />
    Options FollowSymLinks
    AllowOverride All
</Directory>
<Directory /var/www/>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    allow from all
</Directory>

Then restart the server

sudo /etc/init.d/apache2 restart

This will make clean urls work in drupal.


First thing is that you need mod_rewrite for Apache to be enabled to be able to use it. See if you have it enabled in /etc/apache2/mods-enabled, and if you don't see a rewrite.load link there what you need to do is:

sudo a2enmod rewrite

then restart the Apache:

sudo /etc/init.d/apache2 restart

Then, as mentioned by kiamlaluno, you need to enable Clean URLs, and install Pathauto and Token modules.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号