For testing purposes, I would like to append a query string (let's say testing=true) to any url requested from my website.
E.g. I want to change
example.com
example.com/product
example.com/search?q=string
to
example.com?testing=true
example.com/product?testing=true
example.com/search?q=string&testing=true
I tried this:
RewriteRule ^/?(.*) http://example.com/$1?testing=true [L,R,NE]
but it breaks the site. Not an expert.
Any ideas?
EDIT:
I should add I'm working with CodeIgniter (PHP) and my current .htaccess looks like this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|public|images|robots\.txt|css)
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
You can use this new rule:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{QUERY_STRING} !(^|&)testing=true(&|$) [NC]
RewriteRule ^ %{REQUEST_URI}?testing=true [L,QSA,R]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|public|images|robots\.txt|css)
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
Related
Need help in forwarding below url with .htaccess rules
https://www.example.com/watch?v=yzwRsQ7rR-o
forward to
https://www.example.com/?url=https://www.youtube.com/watch?v=yzwRsQ7rR-o
I've following exisitng rules
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
Check this redirect with query string
<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_URI} ^watch
RewriteCond %{QUERY_STRING} v=([A-Za-z0-9-]+) [NC]
RewriteRule (.*) /?url=https://www.youtube.com/watch?v=$1 [R=301,L]
</IfModule>
I have the following .htaccess file, when I type http://adidas.localhost/ in the URL the 'store' query variable does not get appended, however when I add a single character for example http://adidas.localhost/1 it will work perfectly fine, but not without any characters after the slash, I've tried everything and haven't been able to come up with a solution, thanks.
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_HOST} ^([^\.]+)\.localhost$ [NC]
RewriteRule ^(.*)$ http://localhost/?store=%1&uri=%{REQUEST_URI} [QSA,L]
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
Try with:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^([^\.]+)\.localhost$ [NC]
RewriteRule ^(.*)$ http://localhost/?store=%1&uri=%{REQUEST_URI} [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
I need your help I am trying to change my URL format but I cannot do that I keep getting Object Not Found error.
Real URL is : http://localhost/website/page.php?pid=about
I want like this url using htaccess http://localhost/website/about.php
My code is:
<IfModule mod_rewrite.c>
RewriteEngine On
#RewriteCond %{HTTP_HOST} !^www\.
#RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php !-f
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(([a-zA-z0-9\_\-\+]+))\.html|([a-zA-z0-9\_\-]+)\.php$ page.php?pptype=$2&pppage=$3&id=$4 [QSA,NC,L]
</IfModule>
Try it like this for your url similar to http://localhost/website/about.php
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewrwiteRule ^([\w-]+)/([\w-]+).php$ $1/page.php?pid=$2 [L]
Use this in your .htaccess:
RewriteEngine On
RewriteRule ^website/([^/]*)\.php$ /website/page.php?pid=$1 [L]
It will leave you with the URL: http://localhost/website/about.php
I am guessing this question has been asked many times, but i could not find one that would perhaps give me what I need.
So.. I can access the scripts by the following url's:
http://website.com/index.php/hello/world
http://website.com/hello/world
Both go to index.php which parses the input (hello/world in this example).
this is my .htaccess:
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php?path=$1&%{QUERY_STRING} [L]
</IfModule>
However. When the site is accessed like this:
http://website.com/index.php/hello/world
the RewriteRule outputs something similar to index.php?path=index.php/hello/world
I want to remove that index.php after path= in the RewriteRule
Your .htaccess file should look like this (notice the new rule that checks if index.php is a part of url):
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^index.php/(.*)$ index.php?path=$1&%{QUERY_STRING} [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php?path=$1&%{QUERY_STRING} [L]
</IfModule>
Try this
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
Modifying answer from Stackoverflow answer to suit this question
The .htaccess:
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
# Redirect user
RewriteCond %{THE_REQUEST} ^.*index.php.*
RewriteRule ^(.*)index.php(.*)$ $1$2 [NC,R=301,L]
# Handle the query to PHP
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php?path=$1&%{QUERY_STRING} [L]
</IfModule>
My current .htacces file looks like this:
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|assets|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]
What I am trying to accomplish (as well as the above) is to change a url such as http://domain.com/pages/pagename to something like http://domain.com/index.php/pages/view/pagename.
Keeping in mind that I still require urls without the /page/ part such as http://domain.com/search to go to http://domain.com/index.php/search. I am working with CodeIgniter.
What I have come up with so far is:
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|assets|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]
RewriteCond %{REQUEST_URI} ^/pages/(.*)
RewriteRule ^(.*)$ ./index.php/pages/index/$1 [L,QSA]
But it isn't working.
Try this one:
RewriteEngine on
# do not do anything for already existing files
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule .+ - [L]
# /pages/ specific rule
RewriteRule ^pages/(.*)$ index.php/pages/index/$1 [L]
# everything else
RewriteRule ^(.*)$ index.php/$1 [L]
The above assumes that http://domain.com/pages/ is not a real folder.
RewriteRule ^pages/(.*) /index.php/pages/index/$1