3

I am currently using htaccess to force to use index.php file. like given below.

    RewriteEngine On
    RewriteBase /

    RewriteCond %{HTTP_HOST} !^www\.
    RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php?/$1 [L]

In current website it has some uploaded contents like

  • uploads/item/11.jpg

  • uploads/item/12.jpg

  • uploads/item/13.jpg

I wanted to re re-write it like.

  • uploads/item/11.jpg => uploads/item/11-itemName11whatEver.jpg
  • uploads/item/12.jpg => uploads/item/12-itemName12whatEver.jpg
  • uploads/item/13.jpg => uploads/item/13-itemName13whatEver.jpg

Can anyone help me to find RewriteCond and RewriteRule for this.

Updated

Updated htaccess

    RewriteEngine On
    RewriteBase /

    RewriteCond %{HTTP_HOST} !^www\.
    RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]


    RewriteCond %{REQUEST_FILENAME} uploads-
    RewriteRule ^uploads-([^/]+)-([0-9]+)-[^.]+\.([a-z]+)$ uploads/$1/$2.$3 [L,NC]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php?/$1 [L]

This helps me to make the URL look like

www.store45.loc/uploads-item-11-sample-watch.jpg

2
  • What is the URL you want to show in browser?
    – anubhava
    Oct 17, 2014 at 7:02
  • @anubhava i wanted to show "site.com/uploads/item/11-itemName11whatEver.jpg"
    – Arjun Raj
    Oct 17, 2014 at 7:11

1 Answer 1

3
RewriteCond %{REQUEST_FILENAME} uploads-
RewriteRule ^uploads-([^/]+)-([0-9]+)-[^.]+\.([a-z]+)$ uploads/$1/$2.$3 [L,NC]
0

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.