我如何在 Symfony 2 上使用 .htaccess 更改我的 URL
How can i change my my URL with .htaccess on Symfony 2
我想仅使用 .htaccess 来更改我的 url,如何将我的 url 从这个 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/add
和 http://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/ [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]
谢谢你,对不起我的英语!
在我看来,最好的方法是保留 symfony 的默认 htaccess,并按照此处的说明配置您的 apache vhost:
http://symfony.com/doc/current/cookbook/configuration/web_server_configuration.html
(如果不是 dude,不要忘记启用 apache 重写:sudo a2enmod rewrite
)
创建虚拟主机文件:
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
我想仅使用 .htaccess 来更改我的 url,如何将我的 url 从这个 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/add
和 http://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/ [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]
谢谢你,对不起我的英语!
在我看来,最好的方法是保留 symfony 的默认 htaccess,并按照此处的说明配置您的 apache vhost: http://symfony.com/doc/current/cookbook/configuration/web_server_configuration.html
(如果不是 dude,不要忘记启用 apache 重写:sudo a2enmod rewrite
)
创建虚拟主机文件:
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