So I'm trying to write a really simple rewrite condition in my .htaccess but I'm a very beginner with it and I can't seem to make it work.
I'm trying to redirect from example.com/me/name to example.com/me?n=name
I've read other people's posts, instructions, tutorials, I can't understand where I'm wrong.
What I tried is this:
RewriteRule (http://example.com/me/*) http://example.com/me?n=*
But it doesn't do anything different.
You can not match against host/domain in Rule's pattern, to rewrite /me/name to /me?n=name you can use the following rule
RewriteRule ^me/((?!index).+)/?$ /me?n=$1 [L]
Related
I try to redirect domain.tld/?cur=usd to domain.tld (there are many curencies, this is only example of one currency - we do not use anymore this solution).
I need to redirect only home with parameter to home without parameter. The other urls worked for me, I'm just having trouble getting work with that one.
I try to search and use online generators but none of the solutions work.
Here is what I am trying:
RewriteCond %{QUERY_STRING} (^|&)cur\=(.*)($|&)
RewriteRule ^$ /? [L,R=301]
// update
before this rule I have only
#bof redirects
RewriteEngine enabled
...and then there are redirects for other URLs, but I tested this rule separately first and the result was the same...
It not redirect me.
Thanks for the help and maybe an explanation of what I'm doing wrong.
RewriteCond %{QUERY_STRING} (^|&)cur\=(.*)($|&)
RewriteRule ^$ /? [L,R=301]
As mentioned in comments, this should already do as you require, providing there are no conflicts with other directives in the .htaccess file.
However, the regex in the preceding condition is excessively verbose for what you are trying to achieve (ie. just testing for the presence of the cur URL parameter).
If you simply want to check for the cur URL parameter anywhere in the query string then the regex (^|&)cur= would suffice (and is more efficient). No need to backslash-escape the literal =. And if the URL parameter always appears at the start of the query string then just use ^cur=.
I found the problem - it was something with the hosting, after a reboot everything started working as expected.
So I can confirm that this rule is fine.
Sorry for question.
I'm trying to get 2 different parts of a url and use them in a rewrite but I can't get it to work
I'd like
http://example.com/account/test-page?h=1&t=2
http://example.com/account/test-page
to rewrite to
http://example.com/page.php?path=account/test-page&h=1&t=2
http://example.com/page.php?path=account/test-page
I've tried a dozen different ways - this is the latest one :
RewriteRule ^http:\/\/example.com\/([^\?.]*)[\?]?([^/]*)$ http://example.com/page\.php?url=$1&$2
but it doesn't work and I'm tearing my hair out !!
could someone tell me where I'm messing up please ?
Please use the following rule instead:
RewriteRule ^(.*)$ /page.php?path=$1 [QSA,L]
The key, here, is the QSA flag, which appends in query string used to the query string already passed to page.php.
To be clear, a request made to /account/test-page?h=1&t=2 will be internally rewritten as /page.php?path=account/test-page&h=1&t=2.
I am trying to make it for when a client loads the website:
http://www.example.com/docs/example
To actually load the address:
http://www.example.com/docs.php?doc=example
But not have it redirect. I have had mixed success with this, but it seems that there is not clear documentation on how this specific rewrite rule is made. If I actually knew regular expressions, then it would make this a lot easier i understand, but I am seeking some help on how to perform this.
Thanks so much!
In the htaccess file in your document root, add these rules:
RewriteEngine On
RewriteRule ^/?docs/(.*)$ /docs.php?doc=$1 [L]
Don't use the http://hostname/ or the R flag and it shouldn't redirect.
I'm trying to make my dynamic URL's into static looking URL's.
This is a typical URL that I now have:
http://www.somedomain.com/design/index.php?p=about
I would like it to be: http://www.somedomain.com/about
So far, I've gotten it to look like this: http://www.somedomain.com/design/about.html
This is the Rewriterule I'm using: RewriteRule ^([a-z]+).html$ index.php?p=$1 [L]
How would I modify it so it would look like this: http://www.somedomain.com/about?
Thanks for any/all help!!!
Very much appreciated!
Using rewrite rules to give 'static' URI is NEVER a good idea.
A few other ideas you can use:
Make the 'about' page a directory (folder) with a file called index.php or index.html in it. This way the URL shows http://example.com/about/ and the information you wish can still be displayed as needed.
Use the POST method instead of GET methods. This will display as http://example.com/about.php (Note: there is no ? or other parameters behind that.)
Utilize both methods to give a 'seamless' URI on page transitions.
Rick, you're on the right track. You need to read the Apache rewrite documentation. For your docroot/.htaccess start it with:
RewriteEngine On
RewriteBase /
Then generalised version of your rule:
Rewrite Rule ^(\w+)$ index.php?p=$1 [L]
This will rewrite any requests which are for a word string to index.php. You need to be aware that the rewrite engine rescans the .htaccess file if a match has occured so you need to make sure that you don't create a loop. In this case the replacement string has a "." in it and the pattern doesn't, so this won't occur, but for more complex cases you may need to 'guard' the rules with one or more RewriteCond statements. Again, read the Apache documentation.
I'm trying to rewrite part of an url as I've changed a CMS and still want Google to find my articles.
I have:
www.mywebsite.com/vision
www.mywebsite.com/vision/40/some-article-name
and want to rename them:
www.mywebsite.com/news
www.mywebsite.com/news/40/some-article-name
Any hints as to the re-write rules or where I can look? I'd like to change the rules in my .htaccess file.
# Activate Rewrite Engine
RewriteEngine On
# redirect /vision to /news
RewriteRule ^vision$ http://www.mywebsite.com/news [R=301,NC]
# redirect /vision/bla-bla to /news/bla-bla
RewriteRule ^vision/(.*)$ http://www.mywebsite.com/news/$1 [R=301,NC,QSA]
In theory (and practically) these 2 rewrite rules can be combined, but then if you have URL that starts with "vision" (like this, for example: /visions/hurray) then such rule may redirect wrong URLs. Therefore I have done it via 2 rules which is much safer.
Try: http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html
or: http://httpd.apache.org/docs/2.2/mod/mod_substitute.html if you want to change links in the html content returned to the browser.
Here is an example of how I might do the rewrite I think you're after...
RewriteRule ^(.)/vision/(.)$ $1/news/$2
This may be to broad of a rewrite scope in which case this may be better...
RewriteRule http://www.mywebsite.com/vision/(.*)$ http://www.mywebsite.com/news/$1
Also learning the basics of regex will be a needed skill for doing any complex rewriting IMO.
Hope that helps.