How do I remove subfolders names from URL?
For example:
mywebsite.com/wp-contents/uploads/2019/02/image.jpg
mywebsite.com/wp-contents/uploads/user/demo/2019/02/image2.jpg
Then the same URL without the subfolder's name:
mywebsite.com/uploads/image.jpg
mywebsite.com/uploads/image2.jpg
INFO: I can only use .htaccess to achieve this.
Try this rules in your .htaccess file
RewriteEngine On
RewriteRule ^uploads\/image\.jpg$ /wp-contents/uploads/2019/02/image.jpg [L]
RewriteRule ^uploads\/image2\.jpg$ /wp-contents/uploads/user/demo/2019/02/image2.jpg [L]
another rule for all /uploads/image***.jpg to /wp-contents/uploads/2019/02/image***.jpg
RewriteEngine On
RewriteRule ^uploads\/(.*)$ /wp-contents/uploads/2019/02/$1 [L]
Related
I have a url http://www.example.com/chatroom/chats.php?chat=hey dear
I want a url to be http://www/example.com/chatroom/chats/hey dear
where chatroom is an alias folder.
my apache document root is pointing to a specific folder as DocumentRoot
/var/www/html/myweb
I am trying like
RewriteEngine on
RewriteBase /
RewriteRule ^chatroom/([A-Za-z0-9-]+)/?$ chats.php?chat=$1 [NC]
Its saying
404 not found.
Set QSA flag for your rule and try
RewriteRule ^chatroom/(.*) chats.php?chat=$1 [QSA,L]
QSA - Query String Append
You need to place a .htaccess file in chatroom folder with the following content.
Options +FollowSymLinks
RewriteEngine on
RewriteRule chats/(.*) chats.php?chat=$1
Or the following if placing in root folder
RewriteEngine On
RewriteRule ^([^/]*)$ /chatroom/chats.php?chat=$1 [L]
Here are some tools which might help you to generate the such code.
http://www.generateit.net/mod-rewrite/index.php
http://www.webconfs.com/web-tools/url-rewriting-tool/
I need to rewrite only 1 specific URL, to display to visitors specific content: I tried something like, this:
RewriteEngine on
RewriteCond %{REQUEST_URI} example.com/test/2_5/page.html
RewriteRule ^(.*)$ example.com/tt.html [R,L]
I need to rewrite all requests to:
http://example.com/test/2_5/page.html
to
http://example.com/tt.html
how to do this?
thanks,
Redirect /test/2_5/page.html /tt.html
Ok, mod_rewrite
RewriteRule ^/test/2_5/page.html /tt.html [L]
Remove first / if using .htaccess in the site's root folder, not the .conf file. And, typically, the final url should be the full one, with http:// and domain, but this one will work too. If you want to do everything by the rules then
RewriteRule ^/test/2_5/page\.html$ http://example.com/tt.html [L]
Is it possible to somehow change my website links from:
domain.com/category.php?tag=test
domain.com/section.php?tag=test
domain.com/news.php?tag=test
into this:
domain.com/category-test
domain.com/section-test
domain.com/news-test
Thanks and have a good day!
You can achieve this using .htaccess and mod_rewrite. You'll need to create a .htaccess file with the following contents:
RewriteEngine On
RewriteBase /
RewriteRule ^category-([^/]+)/?$ category.php?tag=$1
RewriteRule ^section-([^/]+)/?$ section.php?tag=$1
RewriteRule ^news-([^/]+)/?$ news.php?tag=$1
Now, accessing domain.com/category-test/ will take you to category.php?tag=test.
If you'd prefer to have slashes instead of dashes, you can use:
RewriteRule ^category/([^/]+)/?$ category.php?tag=$1
RewriteRule ^section/([^/]+)/?$ section.php?tag=$1
RewriteRule ^news/([^/]+)/?$ news.php?tag=$1
RewriteRule ^category-([a-zA-Z0-9]+)$ category.php?tag=$1 [NC,L]
RewriteRule ^section-([a-zA-Z0-9]+)$ section.php?tag=$1 [NC,L]
RewriteRule ^news-([a-zA-Z0-9]+)$ news.php?tag=$1 [NC,L]
In "category.php" file get the tag $_GET['tag'];
My mediawiki's localproject name is "wiki_test".and i use following code for localsettins.php file
$wgScriptPath = "/wiki_test";
$wgArticlePath = "/wiki/$1";
require_once("$IP/extensions/ShortUrl/ShortUrl.php"); //
and create one file in the root(means in my project folder) .htaccess file.and put following code in that
RewriteEngine On
# Short url for wiki pages
#RewriteRule ^/?wiki(/.*)?$ %{DOCUMENT_ROOT}/mediawiki_test/index.php/ [L]
# Redirect / to Main Page
RewriteRule ^/*$ %{DOCUMENT_ROOT}/mediawiki_test/index.php [L]
and try for short url but give error like"Object not found!". so plz give me idea........
If you are placing your .htaccess in mediawiki_test directory then this code should work:
RewriteEngine On
RewriteBase /mediawiki_test/
RewriteRule ^index\.php$ - [L]
RewriteRule ^ index.php [L]
I have the following htaccess rewrite rules
RewriteRule ^shows-watch/(.*).html?$ show.php?name=$1
RewriteRule ^shows-watch/(.*)/season-(.*).html?$ show.php?name=$1&season=$2
RewriteRule ^shows-watch/(.*)/season-(.*)/episode-(.*).html?$ show.php?name=$1&season=$2&episode=$3
Now the thing is, the first rewrite rule works just fine
RewriteRule ^shows-watch/(.*).html?$ show.php?name=$1
It's just when I try using the others, only name get variable is being passed and not
$_GET['season']
or
$_GET['episode']
i know it's most likely something simple I'm missing or have done, but I just can't seem to get it working.
Give this a try:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteRule ^shows-watch/([^/]+)/season-([^/]+)/episode-([^/]+).html?$ show.php?name=$1&season=$2&episode=$3 [QSA,NC,L]
RewriteRule ^shows-watch/([^/]+)/season-([^/]+).html?$ show.php?name=$1&season=$2 [QSA,NC,L]
RewriteRule ^shows-watch/([^.]+)\.html?$ show.php?name=$1 [QSA,NC,L]
The order is very important so they don't overlap you also need the L flag to stop when needed.
This assumes your .htaccess is on the root folder of your domain along with the show.php file and that you are accessing it like this:
domain.com/shows-watch/Show Name.html
domain.com/shows-watch/Show Name/season-1.html
domain.com/shows-watch/Show Name/season-1/episode-10.html
The first line gets all the links because it matches all the links.
Try reverse the order:
RewriteRule ^shows-watch/(.*)/season-(.*)/episode-(.*).html?$ show.php?name=$1&season=$2&episode=$3
RewriteRule ^shows-watch/(.*)/season-(.*).html?$ show.php?name=$1&season=$2
RewriteRule ^shows-watch/(.*).html?$ show.php?name=$1
Or you can exclude slashes like this:
RewriteRule ^shows-watch/([^/]*).html?$ show.php?name=$1
RewriteRule ^shows-watch/([^/]*)/season-([^/]*).html?$ show.php?name=$1&season=$2
RewriteRule ^shows-watch/([^/]*)/season-([^/]*)/episode-([^/]*).html?$ show.php?name=$1&season=$2&episode=$3