Symfony Routing Issue After Changing Apache Configuration File

I have an issue with my symphony project, Let me explain step by step what changes I made.

  1. My old working project:

URL of my old project looks like http://127.0.0.1/my_project/something

httpd.conf file

Alias /my_project/something/auth /opt/www/my_project/auth
<Directory /opt/www/my_project/auth>
    AllowOverride None
    Require all Granted
</Directory>

Alias /my_project/something /opt/www/my_project/web
<Directory /opt/www/my_project/web>
    AllowOverride None
    Require all Granted

    RewriteEngine On
    RewriteBase /my_project/something

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.+).(d+).(bmp|css|cur|gif|ico|jpe?g|m?js|png|svgz?|webp|webmanifest|pdf)$ $1.$3 [L]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ app.php [PT]
</Directory>

And my routes file looks like

routes.yml file

# routes.yml

get_data:
    path:     /api/select2/get-data
    methods:  [GET]
    defaults:
        _controller: 'my_folderControllersIndexController::apiGetData'

The project is working fine with the above configuration.

  1. My new project stops working after below my change:

Now I want to change the URL like http://127.0.0.1/my_project/something/MY-SLUG/

For that, I changed my httpd.conf file like

new httpd.conf

Alias /my_project/something/auth /opt/www/my_project/auth
<Directory /opt/www/my_project/auth>
    AllowOverride None
    Require all granted
</Directory>

Alias /my_project/something /opt/www/my_project/web
<Directory /opt/www/my_project/web>
    AllowOverride None
    Require all granted
    DirectorySlash Off

    RewriteEngine On
    RewriteBase /my_project/something/
    RewriteOptions AllowNoSlash

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^[^.]+[^/]$ $0/ [R]

    RewriteCond %{QUERY_STRING} !slug=
    RewriteRule ^([a-zA-Z0-9-]+)/(.*)$ $2?slug=$1 [L,QSA]
    RewriteRule ^([a-zA-Z0-9-]+)$ ?slug=$1 [L,QSA]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.+).(d+).(bmp|css|cur|gif|ico|jpe?g|m?js|png|svgz?|webp|webmanifest|pdf)$ $1.$3 [L]
</Directory>

I didn’t change my route.yml file,

I want to set MY-SLUG in session and then use it everywhere in my project, But after changing this I can’t able to access any route of my Symfony project. I don’t want that change in my httpd.conf file to affect my project, I just want MY-SLUG from URL.

Is there any solution for it?

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *