如何在Symfony 2上使用.htaccess更改我的URL

时间:2016-07-01 12:33:20

标签: .htaccess symfony url router

我想仅使用.htaccess更改我的网址,如何更改我的网址:http://s1rd-ubuntu-01/vpscraplist/web/app_dev.php/myproject/到此http://vpscraplist/platform/或此http://vpscraplist/

我的项目中有更多页面http://s1rd-ubuntu-01/vpscraplist/web/app_dev.php/myproject/addhttp://s1rd-ubuntu-01/vpscraplist/web/app_dev.php/myproject/edit ...

我已经使用了脚本但不能为我工作:(

<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On

# Explicitly disable rewriting for front controllers
RewriteRule ^app_dev.php - [L]
RewriteRule ^app.php - [L]

RewriteCond %{REQUEST_FILENAME} !-f

# Change below before deploying to production
#RewriteRule ^(.*)$ /app.php [QSA,L]
RewriteRule ^(.*)$ /app_dev.php [QSA,L]

或者这个:

<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On

# Explicitly disable rewriting for front controllers
RewriteRule ^/web/app_dev.php - [L]
RewriteRule ^/web/app.php - [L]

# Fix the bundles folder
RewriteRule ^bundles/(.*)$ /web/bundles/$1  [QSA,L]

RewriteCond %{REQUEST_FILENAME} !-f
# Change below before deploying to production
#RewriteRule ^(.*)$ /web/app.php [QSA,L]
RewriteRule ^(.*)$ /web/app_dev.php [QSA,L]

谢谢你,对不起我的英语!

1 个答案:

答案 0 :(得分:0)

在我看来,最好的方法是保留symfony的默认htaccess,并按照那里的说明配置你的apache vhost: http://symfony.com/doc/current/cookbook/configuration/web_server_configuration.html

(如果不是dude,请不要忘记启用apache重写:sudo a2enmod rewrite

创建vhost文件:

sudo nano /etc/apache2/sites-available/yoursite.conf

使用:

<VirtualHost *:80>
    ServerName mydomain.net
    ServerAlias www.mydomain.net

    DocumentRoot /var/www/myprojectSymfony/web
    <Directory /var/www/myprojectSymfony/web>
        AllowOverride All
        Order Allow,Deny
        Allow from All
    </Directory>

    <Directory />
            Options FollowSymLinks
            AllowOverride None
    </Directory>


    ErrorLog /var/log/apache2/project_error.log
    CustomLog /var/log/apache2/project_access.log combined
</VirtualHost>

创建虚拟文件后,必须启用它们

sudo a2ensite yoursite.conf

完成后,您需要重新启动Apache才能使这些更改生效:

sudo service apache2 restart