I'm trying to write a RewriteRule in my .htaccess file to add "&group=core.js" to all the strings that end in ".js?ver=*"
I tried to mess around with the parameters but I can't seem to find a solution.
I'm looking to convert all of the links that look like this:
www.website.com/js/scripts.js?ver=4.9.6
to something that look like this:
www.website.com/js/scripts.js?ver=4.9.6&group=core.js
Any help will be much appreciated.
The following should be working:
RewriteRule ^(.*\.js\?ver=[\.0-9]+)$ $1&group=core.js
It can be improved in terms of what version numbers are allowed, but it’s a good starting point.
You can test the regex here: https://regex101.com/r/jPvTax/1
Related
I have a client that has several files whose name is (for example) car.php, car_edit.php, car_review.php. These each come with query strings - so car.php?id=1234 or car_review.php?id=321. They would like the file names to be truck*.php rather than car*.php.
I'm hoping there's a way using htaccess to convert the url string to be truck*.php and use the current car*.php files. Also if possible I'd like to forward any page asking for car*.php to truck*.php.
I've done quite a bit of searching and haven't found an answer to doing this particular thing. Does anyone know how I might do this? Thanks.
You need rewrite rules. Try something like:
RewriteRule ^truck(.*).php$ /car.php?id=$1 [NC,L]
Note: This is untested, so may require tweaking.
RewriteEngine On
RewriteRule ^truck(.*)\.php$ /car$1.php [NC]
ought to do it. It should automatically transfer any URL query string like id=xxx over to the car*.php rewritten URL.
I need to create a series of redirects for personalized urls. They need to go from a directory on my server to a more complex url on another which includes a query string based on the original url. Here is an example:
I would like to rewrite from this:
http://www.mywebsite.com/TestDirectory/John.Doe
to this:
http://their.server.com/adifferentdirectoryname/page.aspx?u=John.Doe&s=lorem&dm=purl
There will be hundreds of these personalized urls I will send out, so I need the solution to account for that so that I don't have to write this for hundreds of names.
Any help is greatly appreciated. Much Thanks!
I think you want something like this:
RewriteRule ^TestDirectory/(\w+\.\w+)$ foo.aspx?u=$1 [R]
The regex \w+\.\w+ matches a word, a dot, and another word. The $1 is replaced with the captured string from the regex. The [R] means to actually redirect the user.
These rules are tough to get just right so I recommend reading through some examples.
I am trying to redirect all requests to subfolders and subfiles in a directory that start with 4 numbers (e.g. 2012) to another directory using the .htaccess file.
For example,
/results/2005-09-19-xxx/* to /event/2005-09-19-xxx/*
and
/results/2005-09-20-file.ext to /event/2005-09-20-file.ext
But not
/results/anything-else/*
From the documents I have looked at I believe I need to use a RewriteCond followed by a RewriteRule. I have been struggling to find a way to both match on the initial 4 numbers and still use them in the redirected link.
I have spent many hours trying to find a solution to this issue, any help or advice would be much appreciated. Thank you.
You don't realy need a rewrite condition, try this rewrite rule :
RewriteRule ^results/([0-9]{4}.*)$ /event/$1 [L,QSA]
This should do the trick:
RewriteRule ^result/([0-9]{4})-([0-9]{2})-([0-9]{2})(.+)$ event/$1-$2-$3$4 [L]
This pattern is: 4 numbers dash 2 numbers dash 2 numbers rest, written in a way that you can easily understand and manipulate at a later date if need be. Everything that fits the pattern will be rewritten - the rest will work as it normally does
Example:
result/2012-02-02-abcd.ext
fits the pattern and will be rewritten to
event/2012-02-02-abcd.ext
What I'm trying to do is rewrite something like
http://www.example.com/folderA/aaa_bb_cc_ddd.php
to
http://www.example.com/folderB/aaa-bb.php
...and I'm have just an awful time figuring out how. Any help or a point in the right direction much appreciated.
This is really going to depend on what these many URL's look like, but for starters you can try this in your htaccess file in your document root:
RewriteEngine On
RewriteRule ^/?folderA/(.*)_cc_ddd\.php /folderB/$1.php [L]
The trick here is figuring out what (.*)_cc_ddd\.php needs to look like. It's entirely dependent on this list of many URL's that you need to alter.
I need to strip out a certain part of my URLS being generated and want to use .htaccess.
Some links are being appended with "&Itemid=XX" after the .html.
Example:
http://www.site.com/conferences-and-events.html&Itemid=XX
XX could be one digit or four so I guess I need a wild card for that part. I know other questions have been answered related to stripping out certain parts of URLs using .htaccess but I can't seem to figure out how to get my specific string stripped out. Any help would be appreciated and sorry for being redundant and dense.
You'll want to use URL rewriting for that, something like this should work;
RewriteEngine On
RewriteRule (.*)&Itemid=\d{1,4}(.*) $1$2 [R]
Explanation: This regular expression matches anything ((.*)) followed by &Itemid= [1 to 4 decimals], followed by anything (another (.*)), and redirects ([R]) to the first anything concatenated with the second anything, thus taking out the &Itemid=xx part.