this is urgent a lot. I need help with some htaccess rules. The clue is when user receives an answer for sth the real url will be www.mydomain.com/results.html/sth but he must can see in his browser only www.mydomain.com/sth only and when i redirect him to home page (www.mydomain.com/index.html) the url has to be www.mydomain.com only.
Thanks
#this is for the www.yourdomain.com/index.html
RewriteRule ^$ index.html [L]
RewriteRule ^/$ index.html [L]
#this is for the results
RewriteRule ^([^/]+)$ results.html?$1
RewriteRule ^([^/]+)/$ results.html?$1
Replace the first 3 lines of code with:
DirectoryIndex index.html
it should have worked by default though
This should work:
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/(results|index)\.html
RewriteCond %{REQUEST_URI} !^/?$
RewriteRule ^(.*)$ /results.html/$1
RewriteRule ^index\.html$ / [R=301,L]
Related
Currently I have an URL that looks like :
www.mywebsite.com/confirm/ZChCQhXNJ5i
The last part of the URL is a random string. I want to remove it from my URL to get something like that
www.mywebsite.com/confirm
I've tried many things such as RewriteRule ^(confirm)/.+$ /$1 [L,NC] but I really don't understand the .htaccess syntax.
Edit 1 - Here is my .htaccess file.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
RewriteRule ^(confirm)/.$ /$1 [L,NC]
</IfModule>
Edit 2 - Your answers helped me, here is the solution I found :
RewriteRule ^(confirm)/(.*) /$1 [L,R=301]
Have you tried using this RewriteRule?
RewriteEngine On
RewriteRule ^(.*)/ZChCQhXNJ5i /$1 [L,R=301]
When I test this it works perfectly. See here: http://htaccess.mwl.be?share=33ae279c-7597-5935-8bf0-d389add54d0a
It successfully changes your URL to www.mywebsite.com/confirm using a permanent 301 redirection.
Think my domain is www.example.com, I want to redirect visitor to www.example.com/main-page . To do that I have written this .htaccess code but its doesn't work.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteEngine On
RewriteRule ^(.*)$/ /main-page/$1 [L]
</IfModule>
Could any one please help me, I can't find the error
To redirect just the home page you will need this rule:
RewriteRule ^/?$ /main-page [L,R=301]
If you don't want URL to change then use:
RewriteRule ^/?$ /main-page [L]
May be just
RewriteRule ^(.*)$ /main-page [L]
Or with the [R] flag to force redirect :
RewriteRule ^(.*)$ /main-page [R]
I have a site which has only ONE file: index.html.
I just want to redirect everything except for http://www.mysite.com/ to http://www.mysite.com/.
That includes /index.html, somephonydir/, somefile.txt, you name it -- I don't care what it is, I just want to redirect to /.
I've tried the following:
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_URI} !^/$
RewriteRule ^.*$ / [L]
This gives me a 500 Internal Server error.
I found the answer. I guess I forgot to actually tell it to redirect. ;)
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/$
RewriteRule ^.*$ / [R=302,L]
RewriteRule ^/(.+)$ /
I have the following rewrite rules:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
# Route requests to /media/* to /projects/media/*
RewriteRule ^media/.* - [NC,L]
# Route all URLs to dispatch.php.
RewriteRule ^(.*)$ dispatch.php [L]
</IfModule>
This redirects everything to dispatch.php, unless the URL is example.com/media/* in which case it will look for the requested file in ./media/. I would like the URL /media/* to be rewritten to look in project/media/*.
Using the rewrite rule RewriteRule ^media/.* project/media [NC,L] results in everything going to dispatch.php.
You'll need to capture the path and append it. Such as:
RewriteRule ^media/(.*)$ project/media/$1 [NC,L]
RewriteEngine on
RewriteBase /
# Route requests to /media/* to /projects/media/*
RewriteRule ^media/(.*)$ project/media/$1 [L]
# Route all URLs to dispatch.php.
RewriteCond %{REQUEST_URI} !^/project/media/.*
RewriteRule ^(.*)$ maintenance.php [L]
Originally I wanted to use the special %{IS_SUBREQ} variable, but I couldn't get it working.
Try these rules:
RewriteRule ^media/.* project/$0 [NC,L]
RewriteRule !^project/ dispatch.php [L]
Solution can be found here.
.htacces
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^([a-zA-Z0-9_-]+)$ sinj.com.hr/index.php?var1=$1 [L]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$ sinj.com.hr/index.php?var1=$1&var2=$2 [L]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$ sinj.com.hr/index.php?var1=$1&var2=$2&var3=$3 [L]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$ sinj.com.hr/index.php?var1=$1&var2=$2&var3=$3&var4=$4 [L]
RewriteRule ^([a-zA-Z0-9_-]+)/$ sinj.com.hr/$1 [R=301,L]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/$ sinj.com.hr/$1/$2 [R=301,L]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/$ sinj.com.hr/$1/$2/$3 [R=301,L]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/$ sinj.com.hr/$1/$2/$3/$4 [R=301,L]
There is folder sinj.com.hr/administracija and when I try to access http://localhost/sinj.com.hr/administracija I am redirected to http://localhost/sinj.com.hr/administracija?var1=administracija
What I would like is when user enters http://localhost/sinj.com.hr/administracija that he is redirected to http://localhost/sinj.com.hr/administracija/index.php. I tried to do this with header("Location:... ") but it always redirects me to http://localhost/sinj.com.hr/administracija?var1=administracija. If folder administracija is renamed then header() function works. Any ideas how to solve this?
Thanks,
Ile
Try this rule to test if the request can be mapped to a directory that contains an index.php file:
RewriteCond %{REQUEST_FILENAME}/index.php -f
RewriteRule ^ %{REQUEST_URI}/index.php
Additionally you can use this single rule to redirect any requests with a URL path that ends with a slash the one without:
RewriteRule ^(.+)/$ sinj.com.hr/$1 [R=301,L]