Adding string to url on htaccess redirect - .htaccess

I have a site that redirects from www.page.com/timmy to www.page.com/
I would like to redirect www.page.com/timmy to www.page.com/#timmy
How would I do this?

I would like to redirect www.page.com/timmy to www.page.com/#timmy
You may try this in one .htaccess file at root directory:
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^timmy /#timmy [L,NC,NE]
For permanent redirection, replace [L,NC,NE] with [R=301,L,NC,NE]

Related

htaccess - all rewrites are being 302 redirected

The relevant parts of the htaccess file are:
Options +SymLinksIfOwnerMatch -MultiViews
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?services/([^\.]+)/?$ http://www.domain.com/somefolder/web_services/instructions.php?service=$1 [L,QSA]
Visiting a relevant page directly also causes a URL redirect. Ive tried removing all the other rules to check for a double redirect and that did not change anything.
Anybody know what would cause EVERY rewrite to be a 302 redirect?
You need to remove http:// from target URI to avoid full redirect:
Options +SymLinksIfOwnerMatch -MultiViews
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?services/([^.]+)/?$ somefolder/web_services/instructions.php?service=$1 [L,QSA,NC]

Getting value with symbol from htaccess

This url
example.com/ad/load.php?id=pay.jpg
would become
example.com/ad/pay.jpg
I tried to do this.. but it doesn't work.
Here is my htaccess (into ad folder)
Options +FollowSymLinks
RewriteEngine On
RewriteBase /ad/
RewriteRule ^(\w+) ./load.php?id=$1
Edit
on this root example.com/ad/ I want to show index.php but it does not show. how to fix it
You regex should allow dot also. Try this in /ad/.htaccess:
DirectoryIndex index.php
Options +FollowSymLinks
RewriteEngine On
RewriteBase /ad/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([\w.-]+)/?$ load.php?id=$1 [L,QSA]

How to add redirect in htaccess for all urls not cotaining specific string?

I'm having some htaccess issues with my wordpress blog. My previous url's were something like
article-name.html
Now I changed the structure to
blog/article-name.html
But I'm still getting 404 for old url's I shared on various other sites. I've tried adding in htaccess a rule, also tried "redirection" plugin with no success:
and in .htaccess I tried:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^((?!blog/).)*.html$ - /blog/$1.html [L]
</IfModule>
Your regex appears to be a problem, try this:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^((?!blog/).+?\.html)$ /blog/$1 [L,R=301,NC]
Change the RewiteBase
But your .htaccess is not an Original WordPress .htaccess. Why you dont use that?

Exclude folders when redirect with htaccess

I have a question.
I want to redirect domain.com/var to domain.com/id=var
I can do that, but when users write a var like my folders, the htaccess redirect to the folder first :/
This is my actual htaccess
Options +FollowSymLinks -Indexes
RewriteEngine On
RewriteBase /
RewriteRule ^([a-zA-Z0-9-+/]+)$ index.php?id=$1 [L]
RewriteRule ^([a-zA-Z0-9-+/]+)/$ index.php?id=$1 [L]
But when the user write for example css, the htacces redirecto to domain.com/css/?id=css
And the second problem is if the user put / after the var, example domain.com/var/
How can I change that? Thx 4 all!!
You need to skip files/directories from rewriting:
Options +FollowSymLinks -Indexes
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([a-zA-Z0-9+/-]+)/?$ index.php?id=$1 [L,QSA]

htaccess rules ignore some strings on url

need help
i have a link like this
http://www.mysite.com/obj/task/land/city/41277/landId/19/Best+Restaurant//Sville%20city
using htaccess
RewriteRule ^l/([0-9]+)/([0-9]+)/?$ index.php?obj=obj&task=land&city=$1&landId=$2
RewriteRule ^l/([0-9]+)/([0-9]+)$ index.php?obj=obj&task=land&city=$1&landId=$2
now my link looks like this
http://www.mysite.com/l/41277/19
what should i add on my htaccess so that my link like this will be accepted
http://www.mysite.com/l/41277/19/Best+Restaurant//Sville%20city
http://www.mysite.com/l/41247/17/Best+parks/Cold%20Province/Platinum%20city
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^l/([0-9]+)/([0-9]+)/? /index.php?obj=obj&task=land&city=$1&landId=$2 [L,QSA,NC]

Resources