2

I am trying to configure Url's in my modules but I am getting a 404 error on accessing the following Url's. This is my products page url example:

http://localhost/jambomall/web/products/products/details-product?deal_key=nvx3FtQf&url_title=3-Jojo-Cat-ponted-heels

I want the Url manager to show this:

http://localhost/jambomall/web/products/details-product/nvx3FtQf/3-Jojo-Cat-ponted-heels

How can I configure my Url manager to display this? This is not working for me.

'products/<deal_key:\w+>/<url_title:\w+>' => 'products/products/details-products'

Here is my web.php

        'urlManager' => [
        'class' => 'yii\web\UrlManager',
        'showScriptName' => false,
        'enablePrettyUrl' => true,
        'rules' => [
            'products/<deal_key:\w+>/<url_title:\w+>' => 'products/products/details-product',
        ],
    ],

and my .htaccess that is in my web folder

RewriteEngine on
# If a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Otherwise forward it to index.php
RewriteRule . index.php 

2 Answers 2

1

your .htaccess seems OK. see the below configuration. This may work for you.

'urlManager' => [
    'class' => 'yii\web\UrlManager',
    'enablePrettyUrl' => true,
    'showScriptName' => false,
    'rules' => array(
         '' => 'site/index',
         'module/<module:\w+>/<controller:\w+>/<action:\w+>' => '<module>/<controller>/<action>',
         '<controller:\w+>/<id:\d+>' => '<controller>/view',
         '<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
         '<controller:\w+>/<action:\w+>' => '<controller>/<action>',
    ),
],
Sign up to request clarification or add additional context in comments.

2 Comments

I am sorry but I do not understand the configurations well. Could you write your example according to my example?
forget other things just add 'module/<module:\w+>/<controller:\w+>/<action:\w+>' => '<module>/<controller>/<action>', and see if it works.
0

You add below code in web.php file...

'components' => [
    'urlManager' => [
        'enablePrettyUrl' => true,
        'showScriptName' => false,
    ],
 ],

And add .htaccess file in web folder for below code....

RewriteEngine on
# If a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Otherwise forward it to index.php
RewriteRule . index.php

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.