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? Commented Oct 17, 2014 at 7:02
  • @anubhava i wanted to show "site.com/uploads/item/11-itemName11whatEver.jpg" Commented 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]
Sign up to request clarification or add additional context in comments.

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.