I have this rewrite rule that redirects me to a sub folder and loads the index.html
Options -Indexes
RewriteEngine On
RewriteBase /
SetEnvIf HOST ^sub.mydomain.de allow
Order allow,deny
Allow from env=allow
Satisfy any
RewriteCond %{HTTP_HOST} ^(www.)?sub.mydomain.de$
RewriteRule ^(/)?$ folder [L,R=301]
so far: this works - but it show the /folder/ inside the url - is it possible
to "hide" the /folder/ in url?
Does somebody has an hint for me?.
Thanks
marek
Remove the R=301 bit from the rule so that it looks like this:
RewriteRule ^(/)?$ folder [L]
Related
I am trying to replace a word in URL and redirect the user using .htaccess
I have this link,
/anyword/akram/anyotherword
and I would like to redirect user to
/anyword/tanger/anyotherword
Here is the code I have tried
RewriteRule ^(.*)akram(.*)$ $1tanger$2 [R=301,L]
Edit
Virtualhost:
<Directory /var/www/html/mywebsite.com/web/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /app.php [QSA,L]
RewriteRule ^(.+)/akram/(.+)$ http://%{HTTP_HOST}/$1/tanger/$2 [R=301,L]
</IfModule>
</Directory>
</VirtualHost>
You can try this rule.
RewriteRule ^(.+)/akram/(.+)$ http://%{HTTP_HOST}/$1/tanger/$2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /app.php [QSA,L]
you should create a new file and save it as .htaccess
After that . Edit the contents of the file. For 301 (Permanent) Redirect: Point an entire site to a different URL on a permanent basis.
# This allows you to redirect your entire website to any other domain
Redirect 301 / http://***/anyword/tanger/anyotherword
I'm answering quite late.
but I think somebody can get it helpful..
RewriteEngine on
RewriteRule /akram/ /tanger/
checkout
Open link, and click on "test"
I want to redirect several pages to a PHP page with GET variables. However, when I try to use an .htaccess file, it redirects but changes the URL. I don't want it to change the URL structure when redirecting. How would I do this?
For example, I want to redirect /fly-snooze-cruise to http://example.com/package_listing.php?package-type=fly-snooze-cruise
and /fly-snooze-cruise/orlando-airport to http://example.com/package_listing.php?package-type=fly-snooze-cruise&airport=orlando-airport
Here is my .htaccess code:
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteRule ^fly-snooze-cruise$ http://www.example.com/package_listing.php?package-type=fly-snooze-cruise [L]
RewriteRule ^fly-snooze-cruise/orlando-airport$ http://www.example.com/package_listing.php?package-type=fly-snooze-cruise&airport=orlando-airport [L]
RewriteRule ^fly-snooze-cruise/orlando-sanford-airport$ http://www.example.com/package_listing.php?package-type=fly-snooze-cruise&airport=orlando-sanford-airport [L]
RewriteRule ^fly-snooze-cruise/melbourne-airport$ http://www.example.com/package_listing.php?package-type=fly-snooze-cruise&airport=melbourne-airport [L]
RewriteRule ^snooze-park-cruise$ http://www.example.com/package_listing.php?package-type=snooze-park-cruise [L]
So i have an .htaccess file that has this in it:
SetEnv APPLICATION_ENV development
RewriteEngine On
RewriteRule ^/path/to/app/(.*)$ /path/to/app/public/$1 [NC,L]
When I go to /path/to/app/ in the browser it displays the directory structure instead of redirecting the server to /path/to/app/public/$1
What am I doing wrong?
Problem is this line:
RewriteRule ^/path/to/app/(.*)$ /path/to/app/public/$1 [NC,L]
Remember: Rewrite doesn't match leading slash. Change your rule to this:
RewriteEngine On
RewriteBase /
RewriteRule ^(path/to/app)/(.*)$ /$1/public/$2 [NC,L]
I think you try build Symfony application? To rewrite rule you need allow override in httpd.conf
DocumentRoot "/var/www/symfony/web"
<Directory "/var/www/symfony/web">
allow from all
AllowOverride All <-------------
Options +Indexes
</Directory>
And if you use directive
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
that mean that if directory exist then display structure else use other RewriteRule
Also try
RewriteRule ^/path/to/app/(.*)$ /path/to/app/public/$1 [QSA,L]
I'd like to implement 301 redirection from http://www.onbip.com/index-en.html to http://www.onbip.com/
In htaccess file I have:
RewriteRule ^.htaccess$ - [F,L] #403 Forbidden
RewriteRule ^inc/ - [F,L]
RewriteCond %{HTTP_HOST} ^onbip\.com
RewriteRule ^(.*)$ http: //www.onbip.com/$1 [R=permanent,L]
RewriteRule ^index-([^\.]+)\.html$ index.php?lang=$1 [L]
I Need to standardize the default page which will be http://www.onbip.com/
How?
In your httpd.conf file, there should already be a line to forbid access to .ht* files that will probably look like this:
<Files ~ "^\.ht">
Order allow,deny
Deny from all
Satisfy All
</Files>
If you want to be redundent, using Files or FilesMatch to protect it would probably be good. If you want to use Rewrite for this, you could throw a 404 as though it doesn't exist.
Here is a redirect (not a mod_rewrite) for a directory /inc to a 404 page
This is at http://httpd.apache.org/docs/2.0/mod/mod_alias.html
Redirect 404 /inc
Now for rewrite
see http://httpd.apache.org/docs/current/mod/mod_rewrite.html
#Set the page (and order of if they are there) to be shown if asked for a directory
#just put index.php if that's all you want
DirectoryIndex index.php index.html
RewriteEngine on
# if not www.onbip.com, then send to http://www.onbip.com
RewriteCond %{HTTP_HOST} !^www\.onbip\.com [NC]
RewriteRule ^(.*)$ http://www.onbip.com/$1 [R=301,NC,L]
# Now if entered "/index-ab.html" then call "/?lang=ab"
# You might want to see about the regex for proper lang, I put something like "en" or "us-en"
RewriteBase /
RewriteRule ^index-([a-z]{2}(-[a-z]{2})?)\.html$ ?lang=$1 [R=301,NC,L]
The last will call "/" from the server which will be "index.php" first if it exists according to directory index.
I have created a site in a subdirectory and would like the site to appear as if it's in the root.
I used the below Mod_Rewrite code to get the site root to redirect to the subdirectory, but I would like the folder the files are held in to not appear.
currently: www.example.com/sitefiles/content/
Would like: www.example.com/content
Thanks
Options +FollowSymlinks -MultiViews
RewriteEngine on
RewriteBase /
RewriteRule ^$ /sitefiles/ [L]
RewriteRule (.*) /sitefiles/$1 [L]
If it needs to be done via .htaccess and mod_rewrite, then use this:
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/sitefiles/
RewriteRule (.*) /sitefiles/$1 [L]
Since you do not explicitly specify the page when website root will be hit, then there is no need for this line: RewriteRule ^$ /sitefiles/ [L]
You need to add condition for your main rewrite rule to prevent rewrite loop (when already rewritten URL gets rewritten again): RewriteCond %{REQUEST_URI} !^/sitefiles/
Well, the directory should have no reason to appear in any listing, and that mod_rewrite you posted should allow you to do as you said. Still, I would go about it a different way:
Options +FollowSymLinks +Indexes
RewriteEngine on
RewriteBase /
RewriteRule ^$ sitefiles/ [L]
RewriteRule ^(.+)$ sitefiles/$1 [L]
Hope this works.