Zend .htaccess redirect to main url - .htaccess

I want to redirect index.php to main url or also /index to main url. I'm using Zend Framework.
My current .htaccess
#Options +FollowSymLinks
#Options -MultiViews
RewriteEngine On
Redirect 301 /index https://sim.ca/
RewriteBase /
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ – [NC,L]
RewriteRule ^.*$ /index.php [NC,L]
I want to make some URL rewriting : if someone types https://sim.ca/index.php or https://sim.ca/index then it will be redirected to https://sim.ca

You should be able to simplify your rules to this:
#Options +FollowSymLinks
#Options -MultiViews
RewriteEngine On
RewriteBase /
#Redirect /index and /index.php to /
RewriteRule ^index(\.php)?$ / [R=301,L]
#Any custom rules should be above here
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ – [NC,L]
#Rewrite all requests that reach this point to the router page
RewriteRule ^ /index.php [NC,L]

Keep your rule like this:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} /index(\.php)? [NC]
RewriteRule ^index(\.php)?/?$ https://sim.ca/ [L,R=301,NC]
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ – [L]
RewriteRule ^ /index.php [L]

Related

Htaccess rewrite localhost/website/index.php?pages=pages/login.php to localhost/website/login

I want to rewrite localhost/website/index.php?pages=pages/login.php to localhost/website/login
This was my attempt, when i open localhost/website/login it says 404 not found
RewriteEngine On
RewriteBase /Domain/
#Make sure it's an actual file
RewriteCond %{REQUEST_FILENAME} -f [OR]
#Make sure its a directory
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
#Rewrite the request to index.php
RewriteRule ^([^/]+)/?$ index.php?pages=pages/$1 [NC,L,QSA]
```
<IfModule mod_rewrite.c>
Options -Multiviews
RewriteEngine On
RewriteBase /website/login
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ index.php?pages=pages/login.php [QSA,L]
</IfModule>
Hello, I don't know exactly what you want to do, but try this

Configure correct htaccess rules

i use htaccess
Options +FollowSymLinks
RewriteEngine on
# Rules
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule detalhe/(.*) detalhe.php?id=$1
i want redirect:
https://example.com/detalhe.php?ID=31&URL=lorem-to-lorem
to:
https://example.com/31/lorem-to-lorem.html
any ideias to help?
You may use an additional rule to handle additional URI segment:
Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteCond %{THE_REQUEST} \s/detalhe\.php\?ID=(\d+)&URL=([^\s&]+)\s [NC]
RewriteRule ^ /%1/%2? [R=301,L,NE]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^(\d+)/(.+)$ detalhe.php?ID=$1&URL=$2 [L,QSA,NC]
RewriteRule ^detalhe/(.*) detalhe.php?id=$1 [L,QSA,NC]

mod_rewrite removes the ?page= fine, get &id= not working

I got my .htaccess working that it is correctly going from:
webshop/index.php?page=home to webshop/home
If I put the id in the URL it still needs to be webshop/product&id=1. What I want to create is webshop/product/1.
I searched a lot of options on the internet but could not get it working. The code below is my .htaccess file.
Options +FollowSymLinks -MultiViews
RewriteEngine On
# Removes index.php from URL
RewriteCond %{THE_REQUEST} /index\.php [NC]
RewriteRule ^(.*?)index\.php$ /$1 [L,R=302,NC,NE]
# Rewrites /home to be /index.php?page=home
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^webshop/([^/]*)$ /webshop/?page=$1 [QSA]
Hope you guys can help me out.
You can use:
Options +FollowSymLinks -MultiViews
RewriteEngine On
# Removes index.php from URL
RewriteCond %{THE_REQUEST} /index\.php [NC]
RewriteRule ^(.*?)index\.php$ /$1 [L,R=302,NC,NE]
# skip all files and directories from rewrite rules below
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
# Rewrites /webshop/product/1 to be /webshop/index.php?page=product&id=1
RewriteRule ^webshop/([^/]+)/(\d+)/?$ /webshop/?page=$1&id=$2 [NC,QSA,L]
# Rewrites /webshop/home to be /webshop/index.php?page=home
RewriteRule ^webshop/([^/]*)$ /webshop/?page=$1 [NC,QSA,L]
You can change (\d+) to ([^/]+) if your id is not only a number

Pretty URL for .html with parameters

I have a website which consists only from .html frontend and I want to have pretty URLs. My goal is to create something like this
http://test.com/mypage.html => http://test.com/mypage
http://test.com/mypage1.html => http://test.com/mypage1
and for one specific page
http://test.com/my-prettlink.html?id=1 => http://test.com/my-prettlink/1
I tried this .htaccess which is located in project root but only removing .html works.
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^ %{REQUEST_URI}.html [L]
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^my-prettylink/(\d+)*$ ./my-prettylink.html?id=$1
More specific rules should come before general rules. So, try:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /subdirectory/
RewriteCond %{THE_REQUEST} ^GET\ /(subdirectory/my-prettylink)\.html\?id=(\d+) [NC]
RewriteRule ^my-prettylink\.html$ /%1/%2? [R=301,L]
RewriteCond %{THE_REQUEST} ^GET\ /(subdirectory/.+)\.html [NC]
RewriteRule ^ /%1? [R=301,L]
RewriteCond %{SCRIPT_FILENAME} -d [OR]
RewriteCond %{SCRIPT_FILENAME} -f
RewriteRule ^ - [L]
RewriteRule ^my-prettylink/(\d+)$ my-prettylink.html?id=$1 [L]
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(?!js|css) %{REQUEST_URI}.html [L]
and also add <base href='/subdirectory/' /> in header

how to change .htaccess of zend framework

I want my first url should be unique
1) https://abc.com/index
2) https://abc.com/index/
3) https://www.abc.com/
4) https://www.abc.com/index
i want if some one type above url then user will redirect to https://abc.com/
Please help me I am new to zend framework
my .htaccess code is here
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} /index(\.php)?[\s?] [NC]
RewriteRule ^(.*?)index\.php$ /$1 [L,R=301,NC,NE]
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ – [L]
RewriteRule ^ /index.php [L]
Please help me to figure this out.
Put this rule as your first rule in your DOCUMENT_ROOT/.htaccess file:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} \s/+index(\.php)?/?[\s?] [NC]
RewriteRule ^index(\.php)?/?$ https://abc.com/ [L,R=301,NC]
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ – [L]
RewriteRule ^ /index.php [L]

Resources