Change (&) in url to (-) with htaccess - .htaccess

Can't find the solution. Of course I want to change the (=) as well.
I have look and have searched for any examples but could not find anything.
This is what I have:
/family/vicks&record=john&generation=10
I would like:
/family/vicks-record-john-generation-10.php

Related

Is there a quick way to delete everything between certain tags, e.g. <head> and </head>, throughout the whole project (multiple pages) in VS Code?

I am trying to find a way to remove all from a tag pair in VS Code.
I’ve been using Notepad++ for this purpose, but for some unknown reason it doesn't work all the time. So, I hope if there is such a possibility in VS Code, it’d be more reliable.
Here is the instruction for Notepad++:
Search for -
<wp:post_name>[^<>]+</wp:post_name>
and replace all with -
<wp:post_name></wp:post_name>
Is there anything like this in VS Code?
I’d really appreciate it if someone can help.
Before using what is suggested in this solution, backup your files, and run the search and replace on a small sample. Be sure to check the outcome to all the possible combinations you can have in your files.
You can achieve what you need with Notepad++ (and SublimeText 3, with RegEx search and replace), and this answer will cover that. Since I've never used Visual Studio Code, I can't say if it will work in it as well.
Consider the following regular expression.
<foo>(.*?)<\/foo>
If we were to apply it to the following text:
<foo><some special chars>!##$%^&*</foo> sure, why not
<foo>Lorem</foo>
<foo>ipsum</foo>
<foo>sit</foo>
<foo>dolor</foo>
<foo>amet</foo>
<bar>elm stuff</bar>
more stuff for you <foo> something </foo> and even more stuff <foo>yes</foo>
it would match all the parts of the text which begin with <foo> and end with </foo>, regardless of what's between them.
If you want to play around with this, I've created an example here.
As far as using this in Notepad++, open the search window, navigate to the Find in files tab, and set it up like in the following image.
You would, of course, need to change the search and replacement strings to those you plan on using, optionally set up a file extension for which to do the replacement (Filters), and set the directory in which to perform find-and-replace.
Limitations
1. Nesting
In case your text contains nested tags of the same kind, like this:
Let's deal with nesting: <foo> some text <foo> a child foo!</foo> let's close the parent</foo>
doing the suggested RegEx search and replace, will turn the previous line of text into this:
Let's deal with nesting: <foo></foo> let's close the parent</foo>
If you don't have nested tags of the same kind, you should be in the clear. Unless...
2. Newlines
The provided RegEx will not match cases where your opening tag shows up in one line, and the closing tag shows up in another line. To match those, you would need to change the original RegEx:
<foo>(.*?)<\/foo>
to this:
<foo>([\s\S]*?)<\/foo>
\s will match any whitespace character (including newlines), while \S will match any non-whitespace character.

Complex find and replace in notepad++

I'm trying to do a find and replace in notepad++ where i remove the dashes from a set of numbers and letters formatted as following: aa-aaa-nn-nnnnn
I've considered writing a plugin, but it just seems like too much work to be worth it.
Here's an example of what I have and what I need.
I have this: <ISRC>AB-CED-12-34567</ISRC>
And the result should be: <ISRC>ABCED1234567</ISRC>
I've tried finding (A-Z+)-(A-Z+)-(\d+)-(\d+) and replacing this with \1\2\3\4
but then it can't find the "text". If I knew how to write the darned search codes, I could do this myself, but I just can't find a complete guide anywhere.
You're close, you want to use character class:
Ctrl+H
Find what: ([A-Z]+)-([A-Z]+)-(\d+)-(\d+)
Replace with: $1$2$3$4
Replace all
[A-]+ means one or more uppercase letter, if you want to match also lowercase, use [A-Za-z]+

mod_rewrite issues with URL if page title has dashes

I have a page that is normally like this:
http://www.url.com/folder/content.php?name=this-is-the-page-title&item_id=129
As you can see, the title of the page is included in the URL, separated by dashes.
So, I'd like to convert this to the following with mod_rewrite:
http://www.url.com/this-is-the-page-title-129.html
For this, I use a mod_rewrite rule like:
RewriteRule ^([^-]*)-([^-]*)\.html$ /folder/content.php?name=$1&item_id=$2 [L]
Unfortunately, using that rule, I get a 404 error. I think the problem is because the title is separated by dashes (-) and the separator itself is a dash as well, so it likely can't tell the variables from each other or something like that.
When I change the rule from dash (-) to slash (/) like this it works fine:
RewriteRule ^([^-]*)/([^-]*)\.html$ /folder/content.php?name=$1&item_id=$2 [L]
But then the URL becomes:
http://www.url.com/this-is-the-page-title/129.html
...which I don't want as I'd have to rewrite the entire structure of the page.
Is there any way to get it working as
http://www.url.com/this-is-the-page-title-129.html
even with the page title being separated by dashes?
Thank you :)
The problem is, you specify ([^-]*) which means that the matching sub-pattern should not contain any dashes... but your page title might contain them.
So, instead, lets let the first part by anything but slash:
RewriteRule ^([^/]*)-([0-9]+)\.html$ /folder/content.php?name=$1&item_id=$2 [L]
This way, everything before the last dash will go into the first sub-pattern, and digits after the last dash - into the second one.

Add parenthesis to vim string

I'm having a bit of trouble using parenthesis in a vim string. I just need to add a set of parenthesis around 3 digits, but I can't seem to find where I'm suppose to correctly place them. So for example; I would have to place them around a phone number such as: 2015551212.
Right now I have a strings that separates the numbers and puts a hyphen between them. For example; 201 555-1212. So I just need the parenthesis. The final result should look like: (201) 555-1212
The string I have so far is this: s/\(\d\{3}\)\(\d\{3}\)/\1 \2-/g
How might I go about doing this?
Thanks
Just add the parens around the \1 in your replacement.
s/\(\d\{3\}\)\(\d\{3\}\)/(\1) \2-/g
If you want to go in reverse, and change "(800) 555-1212" to "8005551212", you can use something like this:
s/(\(\d\d\d\))\ \(\d\d\d\)-\(\d\d\d\d\)/\1\2\3/g
Instead of the \d\d\d, you could use \d\{3\}, but that is more trouble to type.

how to rewrite in a htacess file

im into SEO and friendly URL's and im trying to create a rule in my htacess file and i need help...
Basically, i have a list of alphabet letters. If the users selects one letter, the db will show all the lyrics that starts with that letter...
so if i click C, there will be a list of lyrics and the the first is 'Car and blues'
So, from this
htpp://www.website.com/lyrics.php?letter=C
i want to do this:
http://www.website.com/lyrics/C/
so far, this is what i have
RewriteRule ^lyrics/$ /lyrics.php?letter=$1 [L]
the rule should be smart enough to pick everything that comes after 'lyrics', in between the 2 slashes, and not what comes after...
Thanks
the rule should be smart enough to pick everything that comes after 'lyrics', in between the 2 slashes, and not what comes after...
Your rule as it stands is looking for exactly lyrics/ with no possibility of anything before or after it (as defined by the ^ and $).
Assuming you're using letters A-Z in only capitals, you can use this:
RewriteRule ^lyrics/([A-Z])/?$ /lyrics.php?letter=$1 [L]
This will look for a single capital letter after the lyrics/ and send that value to the rewrite URL and also match both cases of having a trailing / or not.
the rule should be smart enough to pick everything that comes after
'lyrics', in between the 2 slashes, and not what comes after...
I'd suggest you look into using regular expressions to format your url. See this link

Resources