I want to rewrite a URL.
Let's say you visit http://files.domain.com/uploads/file_name.jpg
How can I use htaccess to write it so I can access it via http://files.domain.com/file_name.jpg?
Thanks.
Try putting following lines in your root .htaccess file
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} ^/[^/]*\.jpg [NC]
RewriteRule ^([^/]*\.jpg)$ /uploads/$1 [L,NC]
Related
How can I do the following on the localhost which will be hosted later online:
I have this link:
http://localhost/shops/shop.php?c=15
I want to rewrite it to http://localhost/shops/shop/15
htaccess is(which is placed in C:\wamp\www\shops folder):
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?RECIPES/(.*?)/?$ /single-product-details.php?=$1 [L]
RewriteRule ^/?SHOP/(.*?)/?$ /shop.php?=$1 [L]
With your shown samples, please try following Rules. Place your htaccess file along with shops folder(not inside it).
Please make sure to clear your browser cache before testing your URLs.
RewriteEngine ON
RewriteBase /shops/
##External redirect to friendly url.
RewriteCond %{THE_REQUEST} \s/shops/(shop)\.php\?c=(\d+)\s [NC]
RewriteRule ^ /%1/%2? [R=301,L]
##Internal rewrite to actual url/files.
RewriteRule ^([^/]*)/(.*)/? $1.php?c=$2 [QSA,L]
When I go to http://www.example.com/youtube/detail/abvcde in my browser, I want to internally rewrite the url to http://www.example.com/youtube/detail.php?id=abvcde. I tried to do this with the following .htaccess, but it gives a 404 error.
Currently my .htaccess looks like this:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) $1.php [L]
Put the following code in a htaccess file in server root directory:
RewriteEngine On
RewriteRule ^youtube/detail/(.+)$ youtube/detail.php?id=$1 [L]
You can put this code in your /youtube/.htaccess
Options -MultiViews
RewriteEngine On
RewriteBase /youtube/
RewriteRule ^detail/([^/]+)$ detail.php?id=$1 [L]
I have this .htaccess file which simply reroute URL from primary link ex- http://www.mywebsitename.com/somepage.php?id=some_id to http://www.mywebsitename.com/somepage/some_id
Here is the code for that-
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} !^www.ashurocks.in$
RewriteRule ^(.*)$ http://www.ashurocks.in/$1 [R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^user/([a-zA-Z0-9]+)$ /user.php?u=$1 [QSA]
RewriteRule ^group/([a-zA-Z0-9]+)$ /group.php?id=$1 [QSA]
RewriteRule ^article/([a-zA-Z0-9]+)$ /article.php?id=$1 [QSA]
It was working properly and I was able to get the content. But now, It's not working. Whenever I visit the URL http://www.mywebsitename.com/somepage/some_id, it does not redirect me to http://www.mywebsitename.com/somepage.php?id=some_id .
Is there something wrong with this .htaccess file code?
OK I got it.
I simply used Options +FollowSymLinks -MultiViews before the line RewriteEngine on and it solved my problem
I'm using .htaccess in my public_html folder to redirect my folders to gets:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/])/?([^/])/?$ index.php?v=$1&t=$2
It is giving me a 404 error though when I type my page:
http://southeast.tv/1/e
But it should redirect to:
http://southeast.tv/index.php?v=1&t=e
Make sure you have all of these lines:
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/])/?([^/])/?$ index.php?v=$1&t=$2
RewriteRule ^([^/]+)(\/)?([^/]+)? index.php?v=$1&t=$3
I need a URL like
mydomain.com/myname/?action=post&data=10
Here in a single PHP page (user.php), I need all myname, post and 10 as GET method variables. How can I get it using .htaccess?
you can add the following to .htaccess
RewriteEngine On
RewriteBase /myname/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [L]