I would like to rewrite with the .htaccess-file in root directory the internal path example.com/app/app-v1/ (including all subdirectories) to example.com/app/in the url, so that everything in the /app-v1/ folder is right behind the /app/ directory in the url.
I tried
RewriteEngine On
Redirect /app/app-v1/ /app/
but that's not working
You may try this code in site root .htaccess:
RewriteEngine On
RewriteRule ^app/((?!app-v1/).*)$ app/app-v1/$1 [NC,L]
(?!app-v1/) is a negative lookahead to avoid rewriting URI starting with /app/app-v1/ to this rule.
Related
I'm trying to rewrite requests such as:
/98fj3JHgf-83j/
which would show that folder's index.html, to:
/98fj3JHgf-83j/rewritten.html
but ONLY for a certain IP address. I'd rather put the .htaccess for this in the site root and forget about it, as the subfolder can be anything (not quite anything - a random string of uppercase and lowercase letters, numbers and dashes).
What I've got just now works, but I have to place the .htaccess in each subfolder: -
RewriteEngine On
# requests from 12.34.56.78 get rewritten.html instead of index.html
RewriteCond %{REMOTE_ADDR} ^12\.34\.56\.78$
RewriteRule ^index.html$ rewritten.html
which is not ideal. A single .htaccess in the root would be great, so I'm guessing a little regex in the above somewhere?
Any help much appreciated!
Try this :
RewriteEngine On
# requests from 12.34.56.78 get rewritten.html instead of index.html
RewriteCond %{REMOTE_ADDR} ^12\.34\.56\.78$
RewriteRule ^([A-Za-z0-9-/]*)?index.html$ /$1rewritten.html
I am new to the .htaccess file.
I want to make pretty URLs but the server always gives me 404 or 500 errors.
For example, I want to redirect
http://www.example.com/dir1
to
http://www.example.com/dir1/file1.html
without showing file1.html in the address bar.
I've tried
RedirectRule /dir1/$ /dir1/file1.html but the server says 404.
The .htaccess is in root.
What should I do?
Remember that .htaccess is per directory directive and Apache strips the current directory path (thus leading slash) from RewriteRule URI pattern.
You can use this rule in root .htaccess:
RewriteEngine On
RewriteBase /
RedirectRule ^dir1/?$ dir1/file1.html [L,NC]
OR use this rule in /dir1/.htaccess:
RewriteEngine On
RewriteBase /dir1/
RedirectRule ^/?$ file1.html [L]
This htaccess rule will do the trick.
RewriteEngine On
RewriteBase /
RedirectRule ^dir1/?$ dir1/file1.html [L]
For the record the terminating /? means that you to redirect links with /dir1 and links with /dir1/
Trying to do a simple URL rewrite with .htaccess but it does not seem to be working.
Want to access http://www.example.com/shop/index.php?route=information/information&information_id=11
using the URL http://www.example.com/MyGreatClub2013
This is what I have in my .htaccess which is stored at the www.example.com root level
RewriteEngine On
RewriteRule ^/MyGreatClub2013$ /shop/index.php?route=information/information&information_id=11 [NC,L]
Am I doing something stupidly wrong?
Remove leading slash:
RewriteEngine On
RewriteRule ^MyGreatClub2013/?$ /shop/index.php?route=information/information&information_id=11 [NC,L,QSA]
mod_rewrite rules when used in .htaccess don't match leading forward slash as .htaccess is per directory.
Here's a decent guide: http://www.javascriptkit.com/howto/htaccess.shtml
Hope it helps.
I want to change the URL from:
http://example.com/Portfolios/iPhone/app
To:
http://example.com/iPhone/app
And same for all URLs like:
example.com/Portfolios/iPad/app
To:
example.com/iPad/app
And from:
example.com/Portfolios/xyz/app
To:
example.com/xyz/app
I have tried a lot but nothing is working for me.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^Portfolios(/.*|)$ $1 [L,NC]
</IfModule>
Enable mod_rewrite and .htaccess through Apache config and then put this code in your .htaccess under DOCUMENT_ROOT directory:
RewriteEngine On
RewriteRule ^Portfolios/(.*)$ /$1 [L,NC,R=302]
Explanation: Above rule is matching URL pattern that starts with Portfolios and have somthing like /Portfolios/xyz/app and puts xyz/app in $1. It makes an external redirection to /$1 i.e. /xyz/app.
These are the flags used:
L - Last Rule
NC - Ignore (No) Case comparison
R - External redirection (with 302)
Once you verify it is working fine, replace R=302 to R=301. Avoid using R=301 (Permanent Redirect) while testing your mod_rewrite rules.
You can also set your root directory as /var/www/Portfolios instead of /var/www/ in /etc/apache2/sites-enabled by writing DocumentRoot line as
DocumentRoot /var/www/Portfolios
instead of
DocumentRoot /var/www/
and also this line
< Directory /var/www/ > changed to
< Directory /var/www/Portfolios/ >
I'm trying to edit my .htaccess file to do the following:
1) Determine if the HTTP_HOST is not my own domain, example.com
2) Determine if it is otherdomain.com/admin/_anything_here_
/admin/ is the specific folder I am looking for, then I don't care what comes after it (but I do need to keep it there). So basically anything that has /admin/ as the first folder and isn't example.com should rewrite to otherdomain.com/admin/_anything_still_here_
It's my understanding that using (.*)$ will "store" the _anything_here_ part and allow me to use it with $1.
I have this so far but it isn't working fully:
RewriteCond ^%{HTTP_HOST}+(/admin.*)$ !^([^.]+\.)*example\.com+(/admin.*)
RewriteRule (.*)$ rewrite/to/here$1/ [L]
Try adding the following to the .htaccess file in the root directory of your site.
You need to replace somefolder with the actual folder you want to rewrite to
RewriteEngine on
RewriteBase /
#if its not example.com
RewriteCond %{HTTP_HOST} !example\.com$ [NC]
#if its admin folder, rewrite it to somefolder
RewriteRule ^(admin/.*)$ somefolder/$1[L,NC]
The above assumes that otherdomain.com and example.com are on the same server with the same root folder.