I need to hide directory from url using htaccess - regex

I need to remove directories from my local website url:
Current url : http://localhost/example/trunk/frontend/www
Needed url : http://localhost/example/frontend
I need to remove trunk and www folders from url without changing files (css, js, images, ...etc) paths.
Can anyone help me please?
Thanks

Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/example/trunk/[^/]*/www [NC]
RewriteRule ^(example)/([^/]+)(/.*|)$ /$1/trunk/$2/www$3 [L,NC]
UPDATE:
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /example/
RewriteRule ^((?!trunk)[^/]+)(/.*|)$ trunk/$2/www$3 [L,NC]

Related

Redirect pages in a subfolder to a new page in same subfolder htaccess

I need to redirect several pages to a new page, the easiest way to explain is this...
http://www.example.com/numbers/0800/bronze.html TO http://www.example.com/numbers/0800/bronze-new.html
http://www.example.com/numbers/0845/bronze.html TO http://www.example.com/numbers/0800/bronze-new.html
Any ideas how to do this in one htaccess rule? Thanks!
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !-new\.html$ [NC]
RewriteRule ^(numbers/.+?)\.html$ /$1-new.html [L,R,NC]

How to redirect to other host using mod_rewrite in Apache

I need to create Rewrite Rule for mod_rewrite in Apache but it's really hard for me to understand this whole syntax.
I have links such as:
http://www.example.com/0001/images/image1.gif
and I need them to redirect it to completely other server like:
http://127.127.127.127/0001/images/image1.gif
Is this achievable?
On example.com enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)example\.com$ [NC]
RewriteRule ^ http://127.127.127.127%{REQUEST_URI} [R=301,L]

.htaccess RewriteRule from download.php?token=something into /download/something

I have this URL:
http://www.example.com/subf/subf2/download.php?token=6309838552568
It is possible to rewrite this url into this url?
http://www.example.com/subf/subf2/download/6309838552568
Note: If someone types a URL like this:
http://www.example.com/subf/subf2/download/6309838552568/sbuf3/subf4
i want to show them an error page.
Answer below
Hint: Include files like JS and CSS need to be refer in absolute paths.
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT/subf/subf2/ directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /subf/subf2/
RewriteRule ^(download)/(\w+)/?$ $1.php?token=$2 [L,QSA,NC]
# to take care of css, js, images
RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_URI} \.php$
RewriteRule ^download/(.+)$ /subf/subf2/$1 [L,R=301,NC]

How redirect from url to the part of this url .htaccess

Can you, please, tell how to make a redirect with apache .htaccess:
from http://www.domain1.com/products/?http://www.domain2.com/sdssds?%dfdf
to http://www.domain2.com/sdssds?%dfdf
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+products/\?([^\s]+) [NC]
RewriteRule ^ %1 [L,R=302,NE]

htaccess RedirectMatch regular expression for URL?

On my Wordpress blog, I used to have a plugin that I no longer need. The plugin used to create a bunch of URLs that looked like this:
http://tambnguyen.com/manage-subscriptions?srp=532&sra=s
with the postID being 532. How do I redirect the query strings so that the above URL will redirected to:
http://tambnguyen.com/?p=532
I've tried a few method without any luck (there's an optional "/" after "manage-subscriptions"
<IfModule mod_rewrite.c>
RedirectMatch 301 ^/manage-subscriptions/?\?srp=(\d{1,5})(.*)$ http://tambnguyen.com/\?p=$1
</IfModule>
Please help. Thanks!
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} ^srp=([^&]+) [NC]
RewriteRule ^manage-subscriptions/?$ /?p=%1 [L,R=301,NC]